Python: casting map object to list makes map object empty?
casting, python-3.x
Solution
A `map` object is a generator returned from calling the `map()` built-in function. It is intended to be iterated over (e.g. by passing it to `list()`) only once, after which it is consumed. Trying to iterate over it a second time will result in an empty sequence.
If you want to save the mapped values to reuse, you'll need to convert the `map` object to another sequence type, such as a `list`, and save the result. So change your:
my_map = map(...)
to
my_map = list(map(...))
After that, your code above should work as you expect.
Problem
I have a map object that I want to print as a list but continue using as a map object afterwards. Actually I want to print the length so I cast to list but the issue also happens if I just print the contents as follows: ``` print("1",my_map) print("1",list(my_map)) print("2",my_map) print("2",list(my_map)) ``` and this gives me the following outputs. ``` 1 <map object at 0x7fd2962a75f8> 1 [(1000.0, 1.0, 0.01, 0.01, 0.01, 0.01, 0.01)] 2 <map object at 0x7fd2962a75f8> 2 [] ``` Why is this happening and how can I avoid it to continue using the map and its contents?