Python select specific column values from enumeration list based on column index list -


in below code: reading file, fetching header row, looking specific header columns , storing indices. iterate through rest of rows , want value of indices.

    import csv        def csvreader(csvfilename):     counter = 10     keymap = []     header = ["test1","test2"]     open(csvfilename,'r') f:         reader = csv.reader(f,skipinitialspace=true)         firstline = true         print(reader)         row in reader:             if counter > 0 , firstline == true:                 print(list(enumerate(row)))                 indexes =[i i, j in enumerate(row) if j in header]                 print(indexes)                 firstline=false                 counter = counter - 1             elif counter > 0:                 = dict(zip(header, map((lambda str: row[i] in indexes) ,row)))                 print(a)                 print('test')                 counter = counter - 1         return keymap    if __name__ == '__main__':     csvreader("c:/test.csv") 

folks- response. fixed it. changing below:

a = dict(zip(header, map(str, (row[i] in indexes)))) 

but better solutions, please share them.


Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -