18/18 difference between using 1 for loop and 2 loops


#1



Hey! :slight_smile: so i tried to do exercice 18 in two different ways and they are both ok but i'd like to understand why it works with one loop as well as it does with 2. it might be a dumb question but i'm not so good at programming yet and i'd like to see the difference between the two codes. thanks a lot :slight_smile:


n = [[1, 2, 3], [4, 5, 6, 7, 8, 9]]

def flatten(lists):
    results=[]
    for numbers in lists:
        results=results+numbers
      
    return results

print flatten(n)

#OOOR as it was described in the exercice:
for numbers in lists:  
    for i in numbers:
            results.append(i)


#2

that a difficult question, someone wrote a good answer here, but it requires good understanding :slight_smile:


#3

thanks, i'll check it out :slight_smile:


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.