DEV Community

Discussion on: 10 Awesome Pythonic One-Liners Explained

Collapse
 
paddy3118 profile image
Paddy3118
  1. List mapping

Best to use list comprehensions instead of map in most cases. For your example:

l = [int(x) for x in ['1', '2', '3']]
Collapse
 
devmount profile image
Andreas

I agree, this increases readability even more! Thank you. Is there any other benefit in using list comprehensions instead of the (specially made for this purpose) map() function?

Collapse
 
paddy3118 profile image
Paddy3118

map returns a map object that you then turn into a list. Readability. There are other comprehensions that follow naturally from list comprehensions to generate, for example, dicts, sets and iterators.