Aug-07-2022, 03:23 PM
Hello guys!
I want to get the weekday part from each list in the emailtext list and add it to a histogram.
I want to get the weekday part from each list in the emailtext list and add it to a histogram.
emailtext = [['From', '[email protected]', 'Mon', 'Jan', '5', '09:14:16', '2008'],['From', '[email protected]', 'Fri', 'Jan', '4', '18:10:48', '2008']] weekdays = dict() #creates list with weekdays and adds it to a dictionary for i in emailtext: print(i[2]) weekdays[i] = weekdays.get(i[2],0) + 1I get the correct print values on my prompt, but I can't figure out a way to add them directly to my dictionary without having them go to an intermediary list, and then going through that intermediary list again.
Error:Traceback (most recent call last):
File "C:\Users\lucas\OneDrive\Desktop\Aulas\FreeCodeCamp\Scientific Computing with Python\Exercise 9.2 - forum", line 35, in <module>
weekdays[i] = weekdays.get(i,0) + 1
TypeError: unhashable type: 'list'