I have two lists
list1= [6, 1, 8, 1, 2]
list2= ["Mail Opened", "Mail Not Opened", "Mail Opened", "Mail Not Opened", "Mail Not Opened"]
I was to trying results like
(14,"mailopened") (4,"mailnotopened")
First i tried to convert them Dict but it does not accept duplicate values.
is it Possible to add these lists according to the second list.
Use a
defaultdictand simply add the values fromlist1.This works because
defaultdictsupplies a default value if a key is accessed which doesn’t exist. In this case, it will supply a default of0because we specified that it is aninttype.Use of
enumerate()stolen from @GaretJax. 🙂