Last answered:

22 Apr 2020

Posted on:

21 Apr 2020

1

Resolved: Nested for loop question

  • Course: The Python Programmer Bootcamp
  • Section: For loops
  • Lesson: The power of lists and loops and working together
  • Question: I'm having trouble understanding the code in the example. Could someone give me a breakdown ow what is going on in each line?
Screenshot
1 answers ( 0 marked as helpful)
Posted on:

22 Apr 2020

2
data_copy=data[:]    #here you copy list data to data_copy for i in range(len(data_copy)):  #starting 1st loop    for j in range(0,len(data_copy)-i-1):   #starting 2nd loop         if data_copy[j] > data_copy[j+1]:   # conditions for bubble sorting             data_copy[j],data_copy[j+1]=data_copy[j+1],data_copy[j]   #swapping elements   hope it helps...      

Submit an answer