Sets Output#
Find the output of the following code.
Please don’t run the code before giving your answer.
Question-1#
letters = {'f'}
letters.add('k')
letters.clear()
letters.add('t')
letters.add('t')
letters.add('t')
print(letters)
Solution
{‘t’}
Question-2#
numbers = [5, 8, 6, 1, 5, 5, 6, 7]
numbers = set(numbers)
print(sum(numbers))
Solution
27
Question-3#
state = 'california'
print(len(state))
state_set = set(state)
print(len(state_set))
Solution
10
8
Question-4#
letters = ['a', 'c', 'K', 'T', 't', 'A', 'C', 'a']
letters = [char.lower() for char in letters]
letters = set(letters)
letters = list(letters)
letters.sort()
print(letters)
Solution
[‘a’, ‘c’, ‘k’, ‘t’]