assignment 2 - You can use the bitwise operator ^ to do a xor in python:
ifbool(a) ^bool(b):
assignment 2 - Immediately assign split values to their variables for efficiency.
n1, n2, letter, x, passw=re.split('[-:\s]', line)
assignment 3 - If you're using the x coordinate to calculate the y coordinate by, don't forget to divide y over x's step size xn to make them independent again (x*yn/xn). Though it's probably better never to make the two depend on each other in the first place.
assignment 4 - If you remove values from the list you're looping over the length will change and values will be skipped. Instead make a copy() of it and remove the values from there.
list= [1,4,7,7,2,3,4,5]; copied_list=list.copy(); test= [3,4] # Make three lists
[copied_list.remove(item) foriteminlistifitemintest] # Remove items in test from copied_list
assignment 6 - This is how you sort a string.
sorted_string=''.join(sorted(unsorted_string))
assignment 7 - In Regex look before a certain string with the ?= positive lookahead and find all occurences with re.findall().
re.findall(r'(\d+)*\s*(\w+\s\w+)(?=\sbag)', line)
assignment 7 - Recursion is very powerful, looks very clean, but it's really difficult to grasp.
deffind_bags(color):
teller=0forbaginbags_dict[color]:
teller+=bags_dict[color][bag] +find_bags(bag) *bags_dict[color][bag] # Recursively sum the contents of the bagreturnteller