parsing - How to convert multiple lists to dictionaries in python? -


['*a*', '*b*', '*c*', '*d*', '*f*','*g*'] ['11', '22', '33', '44', '', '55'] ['66', '77', '88', '', '99', '10'] ['23', '24', 'sac', 'cfg', 'dfg', ''] 

need put in dictionary as:

{a : ('11','66','23'),b : ('22','77','24'),c : ('33','88','sac'),d :('44','','cfg')} 

the rows read csv file:

import csv csvfile = csv.reader(open("sach.csv", "rb")) row in csvfile:     print row 

code tried shown above, output of row shown above has many lists. please me put in dictionary format shown above.

zip rows:

with open("sach.csv", "rb") csv_infile:     reader = csv.reader(csv_infile)     yourdict = {r[0].replace('*', ''): r[1:] r in zip(*reader)} 

the zip() function pairing you, passing in reader object * argument python loop on csv rows , pass each row separate argument zip().


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -