Skip to main content

All Questions

-1 votes
3 answers
2k views

Printing odd numbers using Iterators

class OddNum(): def __next__(x): if x%2 != 0: print x def main(): a = iter(OddNum(1)) while next(a)<100: try: print(next(a)) except ...
Jebus Crust's user avatar
0 votes
1 answer
170 views

Adding labels to a data set generated by itertools.product

I am using the python 2.7 iter.product to generate the Cartesian product of three data-sets. This is the same as three nested loops. However before entering the loop I want to print label "Fruit ...
Dave's user avatar
  • 4,358
0 votes
1 answer
757 views

How to use __iter__ and __next__ for iteration in python?

I am trying to learn how iterators, generators and decorators works in python based on the tutorials in this website. In the first example, he/she demonstrate a simple example as below: class Count: ...
Ebrahim Ghasemi's user avatar
-1 votes
1 answer
106 views

How to iterate through file line by line?

I have files with lines of input which I compare to eachother. I have simplified my code alot and obviously it isnt in working python but the main bits of important are the first line for iteration ...
Tom's user avatar
  • 469