I've been hammering my head for some time over this issue but can't seem find a solution for this, hence I ask for the assistance. PS: still a bit new to programming
I have lists in a list:
[(2012, 'january', 'monday'), (2012, 'february', 'monday'), (2012, 'january', 'tuesday')]
What I want is a new list with lists, when giving in the input "monday':
[(2012, 'january', 'monday'), (2012, 'february', 'monday')]
So far my code:
lists = [(2012, 'january', 'monday'), (2012, 'february', 'monday'), (2012, 'january', 'tuesday')]
day = input("Give day: ") #monday
def select_monday(lists, day):
list2 = []
for list in lists:
if list[2] == day: #from here I'm stuck and do not know how to continue
list2.append(list[2])
else:
return None
return list2
Result: None
I have no clue how to get all the lists with a certain value
defaultdict
?