...
Code Block |
---|
a = ["Jake", "John", "Eric"] b = ["John", "Jill"] print(set(a).difference(set(b))) |
Find sorted unique names in two list
Code Block |
---|
def unique_names(names1, names2):
return sorted(set(names1+names2))
names1 = ["Ava", "Emma", "Olivia"]
names2 = ["Olivia", "Sophia", "Emma"]
print(unique_names(names1, names2)) # should print Ava, Emma, Olivia, Sophia |
Dictionary
Info |
---|
Python dictionaries are similar to lists in that they are mutable and can be nested to any arbitrary depth (constrained only by available memory). A dictionary can contain any type of Python object, including another dictionary. The keys in a given dictionary do not need to be the same type as one another, nor do the values. Dictionary elements are accessed by key. Unlike with list indexing, the order of the items in a dictionary plays no role in how the items are accessed. Even though dictionary access does not rely on item order, as of version 3.7 the Python language specification does guarantee that the order of items in a dictionary is maintained once the dictionary is created. |
...