dimanche 1 janvier 2017

Break a for loop with if condition from single line into multiple lines

I am really confused with this part of the code:

newip = []
c = Counter()
for key, group in groupby(logfile, key=lambda e: e.split('.',1)[0]):
   for entry in group:
      c.update(re.findall(r'[0-9]+(?:\.[0-9]+){3}', entry))
   newip.extend(ip for ip, cnt in c.items() if cnt > 10)

How to break these two lines into multiple lines, while doing the same task?

for key, group in groupby(logfile, key=lambda e: e.split('.',1)[0]):
...
   newip.extend(ip for ip, cnt in c.items() if cnt > 10)

Now, I have two questions:

  1. Please explain what these two lines exactly do.
  2. How to break them into multiple lines, while carrying the same task?

Thanks and regards.

Aucun commentaire:

Enregistrer un commentaire