dictionary - Mapping (key, value) (key, value) to (key, (value1, value2)) in Python -


I have a list of Tupe's forms (user, page):

  Tulips = [(Tim, Papufu), (Jane, Pager), (Tim, PageBaz), ...]   

I should loop in this list and a new list or vowel pages per page :

  newlist = [(Tim, [pagefu, pagebuzz]), (Jane, [pager]), ...]   

It is coming that this page is not in user order - as I loop, let me see this New new list will check the exact user already exists or not, and if you update it, the list.

Can someone help me to get through my mental barrier?

@ AVIVinee is fast, but here defaultdict is the solution: Importing from Import default default Tippers = [('Tim', 'Papufu'), ('Jane', 'Pager'), ('Tim', 'PageBaz')] Results = defaultdict (List) key, in tuples value: result [key] .append (value) result # out [8]: defaultdict (& lt; type 'list' & gt ;, '' Tim ': [' page photo ## [9]: {'Jane': ['Pager'], 'Tim': ['PageFoo', 'O', 'Pbz'], 'Jane': ['Pager']} PageBaz ']} Results [edit] Please] [out] [10]: [('T The '[' Pejfu 'Pejbajh']), (] 'Jane', [ 'pager')]

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -