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 ) ]

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

Thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.