Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- my_list = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
- list_comprehension = [x for x in my_list]
- set_comprehension = {x for x in my_list}
- gen_expression = (x for x in my_list) # the language name for these is generator expressions, not generator comprehensions
- print(list_comprehension)
- print(type(list_comprehension))
- print(sys.getsizeof(list_comprehension))
- print()
- print(set_comprehension)
- print(type(set_comprehension))
- print(sys.getsizeof(set_comprehension))
- print()
- print(gen_expression)
- print(type(gen_expression))
- print(sys.getsizeof(gen_expression))
- for val in gen_expression:
- print(val)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement