set comprehension in python

Solutions on MaxInterview for set comprehension in python by the best coders in the world

showing results for - "set comprehension in python"
Lino
24 Sep 2018
1
2# set comprihension
3
4{i+1 for i in range(20)}
5
6{(i,j) for j in range(4,7) for i in range(6,8)}
7
Alessandra
10 Oct 2020
1# set comprehensions are same as List comprehensions but the difference is we use
2# {} instead of [] 
3
4my_set = {char for char in "hello"}
5print(my_set)
6
7num_100 = {num for num in range(1, 101)}
8print(num_100)
9
10square_set = {num**2 for num in range(11)}     # makes the square of the number
11print(square_set)
12
13square_set_even = {num**2 for num in range(11) if num % 2 == 0}
14