简体   繁体   中英

How can I print an element from a list one by one starting by first element and increment until the last one in python

I'm trying to select a specific element in a column:

Clu1 = df1.loc[df1['Cluster1'] == n]
Clu2 = df2.loc[df2['Cluster2'] == n]

the number 'n' need to be selected from a range ex [0, 1, 2, 3] I need to run my simulation and for the first run 'n' should be equal to '0', second run 'n' = 1, third run 'n' = 2, and last 'n' = 3

as solutions that I tried:

values = list(range(0, best_size))
for n in values:
    print(n)
output:
0
1
2
3

The ouptut is a list and I need only one by one

second:

values = list(range(0, best_size))
n = random.choice(values)
n 

the output is random which is not practical in my case

Any Suggestion ? I use Jupyter, python 3

Assuming you use Python 3.x range returns a generator, you don't need to turn that into a list. Just

for n in range(stop_value):
     print(n)

is sufficient.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM