0

Please I'm new to python and I'm trying to understand a line of code. Can someone please explain to me the implications of the addition of the for loop inside brackets with the random integer generator.

Thank you

for i in range( 0, 50 ) :
    ran_values = [ random.randint( 0, 10 ) for i in range( 0, 16 ) ]
2
Contributors
2
Replies
3
Views
4 Years
Discussion Span
Last Post by zeusprog
0

This is a list comprehension, google that term for more information. It is the same as doing the following.

ran_values=[]
for i in range(0,16):
    ran_values.append(random.randint(0,16))

As you can see it requires less code

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.