So far, I've learned about
- list
- set
- dictionary
- generator
comprehensions. Are there any other iterables that can be ''comprehended''? I'm mostly interested in Python 3.
So far, I've learned about
comprehensions. Are there any other iterables that can be ''comprehended''? I'm mostly interested in Python 3.
my_dict = {i:char for i,char in enumerate("Hello, world!")}
my_list = [i**2 for i in range(10)]
my_set = {i**2 for i in range(10)}
my_generator = (i**2 for i in range(10))
In terms of just comprehensions, there aren't any more that I'm aware of. You could of course use a list/generator comprehension within (say) a tuple constructor to create a (in this case) tuple. But that's not a generator per se