Skip to main content
added 5 characters in body
Source Link
ndpu
  • 22.5k
  • 6
  • 58
  • 72

You can also do it with simple generator expression:

for line in (l for f in (file1, file2) for l in f):
    # do something with line

with this method you can specify some condition in expression itself:

for line in (l for f in (file1, file2) for l in f if 'text' in l):
    # do something with line which contains 'text'

The example above is equivalent to this generator andgenerator with loop:

def genlinewithtext(*files):
    for file in files:
        for line in file:
            if 'text' in line:
                yield line

for line in genlinewithtext(file1, file2):
    # do something with line which contains 'text'

You can also do it with simple generator expression:

for line in (l for f in (file1, file2) for l in f):
    # do something with line

with this method you can specify some condition in expression itself:

for line in (l for f in (file1, file2) for l in f if 'text' in l):
    # do something with line which contains 'text'

The example above is equivalent to this generator and loop:

def genlinewithtext(*files):
    for file in files:
        for line in file:
            if 'text' in line:
                yield line

for line in genlinewithtext(file1, file2):
    # do something with line which contains 'text'

You can also do it with simple generator expression:

for line in (l for f in (file1, file2) for l in f):
    # do something with line

with this method you can specify some condition in expression itself:

for line in (l for f in (file1, file2) for l in f if 'text' in l):
    # do something with line which contains 'text'

The example above is equivalent to this generator with loop:

def genlinewithtext(*files):
    for file in files:
        for line in file:
            if 'text' in line:
                yield line

for line in genlinewithtext(file1, file2):
    # do something with line which contains 'text'
added 356 characters in body
Source Link
ndpu
  • 22.5k
  • 6
  • 58
  • 72

You can also do it with simple generator expression:

for line in (l for f in (file1, file2) for l in f):
    # do something with line

with this method you can specify some condition in expression itself:

for line in (l for f in (file1, file2) for l in f if 'text' in l):
    # do something with line which contains 'text'

The example above is equivalent to this generator and loop:

def genlinewithtext(*files):
    for file in files:
        for line in file:
            if 'text' in line:
                yield line

for line in genlinewithtext(file1, file2):
    # do something with line which contains 'text'

You can also do it with simple generator expression:

for line in (l for f in (file1, file2) for l in f):
    # do something with line

with this method you can specify some condition in expression itself:

for line in (l for f in (file1, file2) for l in f if 'text' in l):
    # do something with line

You can also do it with simple generator expression:

for line in (l for f in (file1, file2) for l in f):
    # do something with line

with this method you can specify some condition in expression itself:

for line in (l for f in (file1, file2) for l in f if 'text' in l):
    # do something with line which contains 'text'

The example above is equivalent to this generator and loop:

def genlinewithtext(*files):
    for file in files:
        for line in file:
            if 'text' in line:
                yield line

for line in genlinewithtext(file1, file2):
    # do something with line which contains 'text'
added 58 characters in body
Source Link
ndpu
  • 22.5k
  • 6
  • 58
  • 72

You can also do it with simple generator expressiongenerator expression:

for line in (l for f in (file1, file2) for l in f):
    # do something with line

with this method you can specify some condition in expression itself:

for line in (l for f in (file1, file2) for l in f if 'text' in l):
    # do something with line

You can also do it with simple generator expression:

for line in (l for f in (file1, file2) for l in f):
    # do something with line

with this method you can specify some condition in expression itself:

for line in (l for f in (file1, file2) for l in f if 'text' in l):
    # do something with line

You can also do it with simple generator expression:

for line in (l for f in (file1, file2) for l in f):
    # do something with line

with this method you can specify some condition in expression itself:

for line in (l for f in (file1, file2) for l in f if 'text' in l):
    # do something with line
deleted 3 characters in body
Source Link
ndpu
  • 22.5k
  • 6
  • 58
  • 72
Loading
added 8 characters in body
Source Link
ndpu
  • 22.5k
  • 6
  • 58
  • 72
Loading
added 184 characters in body
Source Link
ndpu
  • 22.5k
  • 6
  • 58
  • 72
Loading
Source Link
ndpu
  • 22.5k
  • 6
  • 58
  • 72
Loading