In Python:
A)
Create an empty set called my_set, add all the odd numbers up to 20 to the set using a for loop, and print the set.
If you have done it correctly, the output should be:
{1, 3, 5, 7, 9, 11, 13, 15, 17, 19}
B)
Create a new set called my_set2 and contain all the odd numbers up to 10.
If you have done it correctly, the code block below should print {1, 3, 5, 7, 9}
C)
Create a set my_set3 that contains all the numbers that are in the set from a) but not in the set from b).
If you have done it correctly, the code block below should print {11, 13, 15, 17, 19}
D)
If you take the cut of the set from b) and the set from c), what do you expect to get then? What about a) and c)?
E)
Use the built-in functions len() and set() to create a function allUnique(lst), which returns True if the list lst contains unique elements and returns False otherwise.
If you have done it correctly, you can test with the code below:
print(allUnique([1, 3, 2, 6, 8]))
print(allUnique([1, 3, 5, 2, 3, 7]))
Output from this should be:
True
False
F)
Use the built-in functions list() and set() to create a function removeDuplicates(lst), which removes duplicates from the list lst and returns the modified list.
You can test your code with the code below:
print(removeDuplicates([1, 3, 5, 2, 3, 7]))
If you have done everything correctly, the output from this should be:
[1, 2, 3, 5, 7]