Join the Stack Overflow Community
Stack Overflow is a community of 6.3 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I am trying to convert for loop to while loop in python and I am not very sure how to do it. Need some help here, thanks! This is what I am working with :

with open('name.csv') as labelcsv:
    reader = csv.reader(labelcsv)
    name = []
    namenumber = []
    for row in reader:
        tags.append(row[0])
        namenumber.append(row[1])
share|improve this question
1  
Why do you want to do that? – Zero Piraeus 18 hours ago
    
reader has built-in funcions specially for for-loop so may not be easy to create while-loop. – furas 18 hours ago
1  
duplicate of reading csv file without for – downshift 18 hours ago
    
Is it possible that you explain what this code does for row in reader: tags.append(row[0]) namenumber.append(row[1]) – Wei Ping Moh 17 hours ago

I don't know what's benefit to change it

with open('name.csv') as labelcsv:
    reader = csv.reader(labelcsv)
    name = []
    namenumber = []
    row = next(reader, None)
    while row:
        tags.append(row[0])
        namenumber.append(row[1])
        row = next(reader, None)

read more: https://docs.python.org/2/library/functions.html#next

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.