I'm getting this error when I try to do this function:
line 40, in <module> d[date].append(item) builtins.AttributeError: 'str' object has no attribute 'append'
I heard that append does not work for dictionaries, how do I fix this so that my function runs?
def create_date_dict(image_dict):
'''(dict of {str: list of str}) -> (dict of {str: list of str})
Given an image dictionary, return a new dictionary
where the key is a date and the value is a list
of filenames of images taken on that date.
>>> d = {'image1.jpg': ['UTSC', '2017-11-03','Happy Friday']}
>>> date_d = create_date_dict(d)
>>> date_d == {'2017-11-03': ['image1.jpg']}
True
'''
d = {}
for item in image_dict:
date = image_dict[item][1]
filename = item
if date not in d:
d[date] = item
elif date in d:
d[date].append(item)
return d
Does anyone know how to fix this?