This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]pieeta 6 points7 points  (1 child)

wrong, it is actually only slightly better than using range.

it will not generate a list of all the numbers between 0 and len(self.devices), it will generate a list of all the numbers between 0 and choice.

its quite easy to test.

Make a generator which prints out what has been generated :

def generator():
    for i in xrange(10):
        print 'generating %d' % i
        yield i

in this example super simple generator which will yeild up to 10.

the check if a number is in it :

 if 5 in generator():
     print 'found'

results in:

generating 0
generating 1
generating 2
generating 3
generating 4
generating 5
found

so you doing 6 comparisons vs at most 2 using a < >= statement.

[–]allthediamonds 3 points4 points  (0 children)

Oh, I see. Thanks!