List comprehension
# [0, 1, 2, 3, 4]
listt = [x for x in range(5)]
Dictionary comprehension
# {0: 0, 1: 1, 2: 2, 3: 3, 4: 4}
dictt = {x:x for x in range(5)}
Set comprehension
# {0, 1, 2, 3, 4}
sett = {x for x in range(5)}
Generator comprehension
# generator object
generator = (x for x in range(5))
Top comments (0)