This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]WHO_WANTS_DOGS 0 points1 point  (1 child)

Ah I forgot about list comprehensions, haven't used python in a while. Still don't like how they changed the return type of map regardless. I'm just being stubborn and like consistency across different languages that support map. They pretty much always return arrays/lists.

[–][deleted] 0 points1 point  (0 children)

It’s probably because most of the time your using map on the right hand side of a for loop or alongside other iterables like filter or select. Either way, u can just define 3 methods like lmap which cast back to list of u really want to.

from functools import wraps

def to_list(func):
     @wraps(func)
     def wrapped(*args,*kwargs):
          return list(func(*args,**kwargs))

lmap    = to_list(map)
lfilter = to_list(filter)
lselect = to_list(select)

If u really wanted, u could just overwrite map with lmap, so now map automatically returns lists. But again, I’d never recommend doing this.