Oct-13-2017, 07:25 AM
(Oct-12-2017, 08:38 PM)snippsat Wrote:gruntfutuk Wrote:How about: (using Python 3)Now do itertools also work for Python 2,and i guess he use Python 3 bye his use of print function.
itertools.islice is cool @gruntfutuk,but for this i had gone for a more simplistic approach as shown in other post with enumerate.
with open('in.txt') as f: for count,line in enumerate(f, 1): if count % 2: print(len(line.strip()))
Your approach is best @snippsat, I was just trying to provide a simpler iter alternative to what @DeaD_EyE suggested as an approach. As the source file is so short, it is all pretty academic. Were the file large, we would be looking for the most efficient approach, avoiding reading anything we don't need to.
I am trying to help you, really, even if it doesn't always seem that way