Re:Specific ways to write better Python (2017)
by xapata on Thursday June 25, 2020 @06:06PM
(#23646313)
No. I put that in places where I receive a generator and want a list.
But, there are plenty of instances of what you're talking about. Take a look at the standard library. Itertools often creates an iterator as the first operation, not knowing whether it received an iterator or some other kind of iterable.
But, there are plenty of instances of what you're talking about. Take a look at the standard library. Itertools often creates an iterator as the first operation, not knowing whether it received an iterator or some other kind of iterable.
https://github.com/python/cpython/blob/384621c42f9102e31ba2c...
If you search for `list` in the CPython code, you'll find many examples of what you're asking about.
Similarly, Pandas often makes a copy of a Series or DataFrame. It might be inefficient, but it keeps the API (more) simple.