Access list of items with list of indices

后端 未结 1 1755
生来不讨喜
生来不讨喜 2021-01-17 14:10

Consider a large list of named items (first line) returned from a large csv file (80 MB) with possible interrupted spacing

name_line =  [\'a\',,\'b\',,\'c\'          


        
相关标签:
1条回答
  • 2021-01-17 14:30

    Try a generator expression,

    data_line = (data_line[i] for i in good_cols)
    

    Also read here about Generator Expressions vs. List Comprehension

    as the top answer tells you: 'Basically, use a generator expression if all you're doing is iterating once'.

    So you should benefit from this.

    0 讨论(0)
提交回复
热议问题