Home > Net >  How to achieve below situation using python list comprehension?
How to achieve below situation using python list comprehension?

Time:10-12

rows = [(d = re.split("\s{2,}|\|", line)) for line in lines if len(d) > 5 and d[0]!='' ]

As in the code snippet shown, I am splitting a list of lines by spaces in each line. I am trying to assign split to a variable d so that I can use it later in if condition and can avoid repetitive split.

Is there way to achieve it?

CodePudding user response:

rows = [d for d in [re.split("\s{2,}|\|", line) for line in lines] if len(d) > 5 and d[0]!='']
  • Related