Member-only story
Set in Python [3]
3 min readOct 29, 2024
Hello,
Press enter or click to view image in full size![]()
81. Set of Numbers Divisible by 5 and 7 in a Range
pythonCopy codedivisible_by_5_and_7 = {x for x in range(1, 101) if x % 5 == 0 and x % 7 == 0} # {35, 70}82. Check if All Elements in Set are Unique (always true for a set)
pythonCopy codeis_unique = len(my_set) == len(set(my_set)) # Always True for a set since elements are unique by nature83. Flatten a Set of Sets of Integers
pythonCopy codenested_set = {{1, 2}, {3, 4}, {5}}
flat_set = {element for subset in nested_set for element in subset} # {1, 2, 3, 4, 5}84. Filter Set to Only Uppercase Strings
pythonCopy codestrings = {"Hello", "WORLD", "Python", "CODE"}
uppercase_strings = {s for s in strings if s.isupper()} # {'WORLD', 'CODE'}85. Find Subset of Set with Length Equal to 2
pythonCopy code




