python matching data output data
扔个三星炸死你
扔个三星炸死你 2017-06-12 09:24:22
0
2
713

I now have a list with the content re=['test1','test2','test3'], and a csv or xlsx or txt with two columns of data

The effect I want to achieve is that if the element of re is equal to column A in the file, then the row of data in column AB of the file will be output. How to implement this specifically?

扔个三星炸死你
扔个三星炸死你

reply all (2)
黄舟

You need to read the file first, then put the result into the array
and then search the value of the array

    学霸
    import csv with open("lookup.csv") as f: reader = csv.reader(f, delimiter=',') dict_lookup = {r[0]:r[1] for r in reader} print(dict_lookup) print(dict_lookup['test2'])

    Output

    {'test1': 'output1', 'test2': 'output2', 'test3': 'output3'} output2

    If the content of lookup.csv is

    test1,output1 test2,output2 test3,output3

    This is a very basic operation of using the csv module, it is recommended to take a look

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!