#70 Python Tutorial for Beginners | Bubble Sort in python | List Sort

Поделиться
HTML-код
  • Опубликовано: 10 янв 2025

Комментарии • 398

  • @shamirroy606
    @shamirroy606 3 года назад +47

    This guys should've been our university teacher. He's so good in explaining complex topics. Thanks a lot Navin Reddy.

    • @P0latalemdar-627
      @P0latalemdar-627 6 месяцев назад

      he wouldve called his students aliens.

  • @nikitasharma2069
    @nikitasharma2069 3 года назад +199

    Btw there is no need to take a temp variable for swapping.
    Python allows a very easy swapping method, just use:
    num[ j ] , num[ j+1 ] = num[ j+1] , num[ j ]

    • @pravintulsijw9513
      @pravintulsijw9513 3 года назад +1

      👍

    • @FukraInsaanLiveShorts
      @FukraInsaanLiveShorts 3 года назад

      I Need help @nikita

    • @jeelaghera5628
      @jeelaghera5628 3 года назад +16

      he has mentioned this code in his series but he is going with old school approach for who are watching bubble sort directly

    • @eclinicalWorks29
      @eclinicalWorks29 3 года назад

      Thanx ❤️

    • @rubbish9231
      @rubbish9231 2 года назад +3

      This is why Phython called scripting language. The syntax you using is using sort function underneath .. basically its doing all steps there in bavkground.

  • @codewithenthronekingsley
    @codewithenthronekingsley 5 месяцев назад +2

    Navin you are just exceptional. I have been cracking my head about this up until now I watched this tutorial. It strange when some tutors claim they teach to beginners and use complex words. Thank you Navin

  • @g17choudhary
    @g17choudhary 6 лет назад +66

    we can directly swap the values
    no need to temp variable
    if arr[j] > arr[j+1] :
    arr[j], arr[j+1] = arr[j+1], arr[j]

  • @RebeccaNamiya
    @RebeccaNamiya Год назад +7

    This is the best bubble explanation I have heard in my research. Keep it up . Good work 👍🏾

  • @AaryanPakhrani
    @AaryanPakhrani 5 лет назад +415

    Did he just call me an Alien?

  • @shenkuulover
    @shenkuulover 3 года назад +6

    Your editing and speaking skills are amazing.
    Straight to the point and really showcases what you need to understand.
    Good job!

  • @glorysonhorace3265
    @glorysonhorace3265 3 года назад +2

    Telusko, you really deserve a thumbs up. DSA never gets easier than this!!!

  • @harshaddaingade9784
    @harshaddaingade9784 4 года назад +4

    def sort(nums):
    for i in range(len(nums) - 1, 0, -1):
    for j in range (i):
    if nums[j] < nums[j + 1]:
    continue
    else:
    nums[j+1], nums[j] = nums[j], nums[j+1]
    nums = [5, 8, 9, 71, 10, 2,589,1,0]
    sort(nums)
    print(nums)

  • @EritreanGamerOfficial
    @EritreanGamerOfficial 2 года назад +1

    i did it like this . it works
    def bubbleSwap(lst):
    x, y = 0, 0
    h = 0
    while h < len(lst):
    for i in range(1,len(lst)):
    if lst[i - 1] > lst[i]:
    x, y = lst[i - 1], lst[i]
    lst[i - 1] = y
    lst[i] = x
    h += 1
    return lst

  • @zakiasmaa6834
    @zakiasmaa6834 4 месяца назад

    I want to express my heartfelt gratitude for all the effort you put into simplifying the topics. Your presence and the way you explain things in the videos bring us joy and radiate positive energy. I hope you continue in this way, and I wish you all the best in everything you do.

  • @nellaiappan8969
    @nellaiappan8969 4 года назад +7

    It had been very very useful for my son during lockdown
    Thank you sir😊☺️

  • @parthbhodia9575
    @parthbhodia9575 4 года назад +10

    This is a really good explanation. I can suggest you to use while loop as well to break out of the for loop if the items in the list are already sorted maybe in the 2nd or 3rd iteration. In that case you will not need to loop through n times.

  • @jackwan358
    @jackwan358 Год назад

    It save me the day to learn this in 10mins! Million thanks!!

  • @chandrashekhartigercharla1633
    @chandrashekhartigercharla1633 3 года назад +1

    Finally I did with one loop..
    Num=[3,6,2,16,11,17,8]
    Def sort(list):
    For i in range(len(num)-1):
    If num[I] > num[I+1]:
    Num[I],num[I+1] = num[I+1],num[I]
    Sort(num)
    Sort(num)
    Print (num)

  • @hamidfarooq7242
    @hamidfarooq7242 6 лет назад +5

    you are amazing took me 7 mins to understand what i have been trying to understand for days

  • @gunasekaranguna1888
    @gunasekaranguna1888 Год назад +1

    def Bubble_sort(n):
    for i in range(len(n)-1,0,-1):
    for j in range(i):
    if n[j]>n[j+1]:
    n[j],n[j+1]=n[j+1],n[j]
    print(n)
    c=int(input("Enter the number of elements in list:"))
    n=[]
    for k in range(c):
    d=int(input("Enter an value:"))
    n.append(d)
    print(n)
    print("The sorted list is",Bubble_sort(n))
    "small modification"

  • @jeetsutaria6802
    @jeetsutaria6802 5 лет назад +2

    thank you sir . tomorrow is my practicals and i have learned from from this video than i have learnt in my entire semister

    • @Rohan-c6y
      @Rohan-c6y 11 месяцев назад

      throw back to 4 years ago when you were learning from this video
      any outputs now? what are you doing now after 4 years are you a full fledged python developer

  • @sreekanthk9412
    @sreekanthk9412 6 лет назад +3

    Instead of using 3rd variable directly we can swap two values nums[j],nums[j+1]=nums[j+1],nums[j]

  • @isaachossain2807
    @isaachossain2807 3 года назад

    Navin Reddy, you are my hero.

  • @anastasiagavrilita6567
    @anastasiagavrilita6567 4 года назад +2

    You are a savior in every single way! (I refer to all of your tutorials!) So grateful that you are doing these tutorials!

  • @justbelieve9754
    @justbelieve9754 3 года назад

    Just outstanding. Love from Pakistan.

  • @chinmaydas4053
    @chinmaydas4053 6 лет назад +5

    Nice sir.. waiting for your video..

  • @gamesgames3318
    @gamesgames3318 2 года назад

    Im dumb at coding so this is a life saver when I can't understand certain parts of the code.

  • @xathunalwarrior8287
    @xathunalwarrior8287 4 года назад +60

    why to make swapping complicated, when you can do this:
    a,b=b,a

    • @nawazmalik5435
      @nawazmalik5435 4 года назад +27

      U have one glass of juice
      And a cup of tea
      If u want to shift (swap) both .
      U need a cup called temp
      U put juice in temp
      Then tea to empty juice glass
      And finally juice to cup .

    • @EylulTurksever
      @EylulTurksever 4 года назад +1

      @@nawazmalik5435 no you don't. in python, you can do it without an extra cup. Xanthunal Warrior's way is correct and better.

    • @kaushalJainer
      @kaushalJainer 4 года назад +5

      lol he also knew that, its just in other languages u dnt have the luxary of swapping this way thats why, once u know the logic u can implement it anywhere you want

    • @madhavbhardwaj2527
      @madhavbhardwaj2527 3 года назад +2

      @@kaushalJainer It is but than you have to remember the variables which have been swapped which will become a more complicated thing. As you have to put b where you are putting a after swapping and vice versa....
      If you are putting a simple logic it is ok and will definitely run on any python software...

    • @anushkasingh1728
      @anushkasingh1728 3 года назад

      Due to the differences in Cs and Ip

  • @vintage-flix-movies
    @vintage-flix-movies 6 лет назад +9

    python is one line code lang
    so swap will be num[j],num[j+1]=num[j+1],num[j]

    • @bonysmoke9190
      @bonysmoke9190 6 лет назад

      Maybe in some cases it will work, but not always. What this "line of code" does is it reverses a list and you get a something like this : list = [3,2,5,1] - before sorting, and after reversing it, you get list = [1,5,2,3]. If i'm not right, please, let me know :)

    • @pranavrk9752
      @pranavrk9752 3 года назад +1

      @@bonysmoke9190 it works in all cases dude. its a python one liner. Because of the way python is build there are tons of one liner, In this case the in the video he use an extra variable temp and 3 lines of code, which can be done with the one liner.

    • @isaachossain2807
      @isaachossain2807 3 года назад

      He was probably trying to teach an algorithm that would apply to all programming languages where a temporary variable is required for swapping. Not all programming languages will support a,b=b,a.

  • @sagnikray5391
    @sagnikray5391 5 лет назад +12

    sir, pls make a video on insertion sort

  • @shams6474
    @shams6474 3 года назад

    vowwww.....I never understood it i college but u made my life easy.

    • @P0latalemdar-627
      @P0latalemdar-627 6 месяцев назад

      *wowwww..... I never understood it in college but you made my life easy.

  • @AmarjeetSingh-ammy
    @AmarjeetSingh-ammy 6 лет назад +12

    Eagerly waiting sir,
    You are awesome,,
    I'm going to give you the name "KNOWLEDGE STACK "
    love from delhi

  • @santhoshsivank8698
    @santhoshsivank8698 9 месяцев назад

    Best explanation ever❤

  • @shahvipul7459
    @shahvipul7459 4 года назад +1

    def Bubble(list_a):
    indexing_length = len(list_a) - 1
    sorted = False
    while not sorted:
    sorted = True
    for i in range(0, indexing_length):
    if list_a[i] > list_a[i + 1]:
    sorted = False
    list_a[i], list_a[i + 1] = list_a[i + 1], list_a[i]
    return list_a
    print(Bubble([5, 3, 8, 6, 7, 2]))

  • @withharshvadhiya
    @withharshvadhiya 2 года назад

    def sort(a):
    for i in range(len(a)-1,0,-1):
    for j in range(i):
    if a[j] > a[i]:
    a[i], a[j] = a[j], a[i]
    this also works same : )

  • @memesv3.093
    @memesv3.093 4 года назад +4

    Here's the easiest way:
    arr = []
    a = int(input("Enter the no of elements"))
    for i in range(a):
    x = int(input())
    arr.append(x)
    for i in range(a-1):
    for j in range(a-i-1):
    if arr[j] > arr[j+1]:
    arr[j], arr[j+1] = arr[j+1], arr[j]
    print("Sorted array is:", arr)

    • @tatapramod277
      @tatapramod277 4 года назад

      could u please explain the a-i-1 part please

  • @subhamoydey3867
    @subhamoydey3867 5 лет назад +1

    sir you solve my doubt in just 7 minutues just like laminar flow of water

  • @MAVERIKTOFA
    @MAVERIKTOFA 4 года назад

    def sort(nums):
    for index1,value1 in enumerate(nums):
    for index2,value2 in enumerate(nums):
    if value1

  • @sameerroshan9542
    @sameerroshan9542 Год назад

    for the outer loop you can also do:
    for i in reversed(range(len(nums))):
    and for swapping you can do this:
    if nums[j] > nums[j+1]:
    nums[j], nums[j+1] = nums[j+1], nums[j]

  • @muhsinshah6502
    @muhsinshah6502 5 лет назад +3

    #Some changes applied
    def sort(list):
    for i in range(len(list)-1,0,-1):
    for j in range(i):
    if list[j] > list[j+1]:
    #look here
    list[j],list[j+1] = list[j+1],list[j]
    nums = [4,7,3,6,2,3,1]
    sort(nums)
    print(nums)

  • @shreyagodson243
    @shreyagodson243 5 месяцев назад

    Thank you for showing in user defined module 😊

  • @kushagragupta4381
    @kushagragupta4381 4 года назад +1

    Mind blowing explanation!

  • @bedbyashlamichhane1541
    @bedbyashlamichhane1541 5 лет назад +2

    we could use :am = [5,8,2,4,8,1]
    aw = sorted(am)
    print(aw)

    • @umxng
      @umxng 5 лет назад

      4:00

  • @chamarthiyashwanth4060
    @chamarthiyashwanth4060 3 года назад

    def bubble_sort(seq):
    min_value = 0
    for i in range(len(seq)-1):
    for j in range(i):
    if seq[j] > seq[j+1]:
    seq[j],seq[j+1] = seq[j+1],seq[j]
    return seq
    is this considered as bubble sort, as in this the sorting is done by taking out the minimum values just like selection sort but with more iterations.

  • @ZesterAcademy-c7r
    @ZesterAcademy-c7r 3 месяца назад

    Love from Bangladesh ❤❤

  • @obbinenireddy4184
    @obbinenireddy4184 6 лет назад +23

    Thank you sir .....sir will you cover all data structure concepts????

  • @abdulfareed2585
    @abdulfareed2585 4 года назад +2

    Hi telusko. The outer loop and inner loop s range is a bit confusing for me.
    I just made the range as simple and it works but IDK whether is this right or not!
    def sort(nums):
    for i in range(len(nums)-1):
    for j in range(len(nums)-1):
    if(nums[j]>nums[j+1]):
    temp = nums[j]
    nums[j] = nums[j+1]
    nums[j+1] = temp
    return nums
    nums = [9,0,1,8,2,7,3,12,5]
    result = sort(nums)
    print(result)

  • @supa.scoopa
    @supa.scoopa 11 месяцев назад

    Perfect! Thank you so much!!

  • @TANUJAS-y6o
    @TANUJAS-y6o 6 месяцев назад

    li=[5,3,8,6,7,2]
    for i in range(len(li)):
    for j in range(len(li)-1):
    temp=0
    if li[j]>li[j+1]:
    li[j],li[j+1]=li[j+1],li[j]
    print(li)

  • @ts37924
    @ts37924 3 месяца назад

    thank ypu so much sir yu explained each detail ^^

  • @Rajadahana
    @Rajadahana 2 года назад +3

    We have covered swapping in an earlier lesson in detail. There we discussed 3 methods as I remembered.
    So it is time to put that knowledge to work, without using a 3rd variable. (I learnt this from you)
    nums[j], nums[j+1] = nums[j+1], nums[j]

  • @Hassam_Haider
    @Hassam_Haider 3 года назад

    thank you very much Sir really, you helped me so much with this

  • @dhruv_it_fitness
    @dhruv_it_fitness 4 года назад

    thank you so much sir.i will be thankful to you.with the help of you i easily learn python

  • @vishnuvardhanreddy8584
    @vishnuvardhanreddy8584 6 лет назад +1

    sir u r awsomee i love this python tutorials and i shared to my friends

  • @Jonzy6ix
    @Jonzy6ix Год назад

    Thanks a lot you made it so simple ❤❤

  • @akhilkrishna5282
    @akhilkrishna5282 3 года назад +1

    Navin can we do it this way? - we create a empty list and do linear search for the greatest value or lowest value and append it to the empty list and remove it from the original list .....do this a few more times and the original list becomes empty and the empty list becomes sorted....i tried and it worked so i thought commenting would help other programmers get different ideas on how to solve the same problem...

  • @anantprakashgupta937
    @anantprakashgupta937 4 года назад

    very helpful sir thank you

  • @sumitgupta-wf4db
    @sumitgupta-wf4db 6 лет назад +1

    Sir you are giving my quarry answer
    Thanks for that I have find my answer without your help

  • @shubhampawar9745
    @shubhampawar9745 4 года назад +1

    Also Using sorted function
    N=[1,4,5,5,7, 8,7,5,9,7]
    Print (sorted(N))

  • @DeepakKumar-uz4xy
    @DeepakKumar-uz4xy 6 лет назад +4

    why take second for loop. can't we use if function directly by direct puttind swap function.
    for i in range(len(list)):
    if list[i]>list[i+1]:
    list[i], list[i+1] = list[i+1], list[i]

    • @sagarrao79
      @sagarrao79 5 лет назад

      if we use only one for loop, only one value sorted to last like below
      [3, 5, 6, 2, 4, 8]
      to repeat same thing we need to use second for loop.
      yes we can use swap a,b= b,a
      def sort(list):
      for i in range(len(list)-1,0,-1):
      for j in range(i):
      if list[j] > list[j+1]:
      list[j],list[j+1]=list[j+1],list[j]
      nums=[5,3,6,8,2,4]
      sort(nums)
      print(nums)

    • @alexw.e.1390
      @alexw.e.1390 5 лет назад

      @@sagarrao79 Please explain this to me: for i in range(len(list)-1,0,-1): I am so confused as to how this works and can't seem to figure it out on my own.
      Thanks

    • @navinyadav9693
      @navinyadav9693 5 лет назад

      @@alexw.e.1390we need to check the values from start till end. when i=5(in this program) j runs from 0 till 5 and the largest value, i.e 8 gets shifted to last place. now i becomes 4( since -1) and j runs from 0 to 4 and the next largest value gets shifted to second last place. this goes on until nums is sorted. i is taken in reverse so that j can check until last value.
      if this didn't help please debug the program. It will help you understand what is happening step by step.

  • @deepakg3003
    @deepakg3003 4 года назад +1

    superb sir

  • @arshgupta5737
    @arshgupta5737 4 года назад

    def sort(self):
    for i in range(a-1,0,-1):
    for j in range(i):
    if list[j]>list[j+1]:
    temp=list[j]
    list[j]=list[j+1]
    list[j+1]=temp
    a=int(input("Enter the no. of elements you want to enter in the list "))
    list=[]
    for i in range(a):
    li=int(input())
    list.append(li)
    print("Unsorted list is: ",list)
    sort(list)
    print ("Sorted list is: ",list)

  • @pratikb8131
    @pratikb8131 5 лет назад +2

    What's difference between bubble and insertion sorting

  • @akshay4081
    @akshay4081 6 лет назад

    No need of temp..Directly swapping
    def sort(lst):
    for i in range(len(lst)-1,0,-1):
    for j in range(i):
    if lst[j]>lst[j+1]:
    lst[j],lst[j+1]=lst[j+1],lst[j]
    print[lst]
    lst=[3,2,6,4,9,7,5]
    sort(lst)

  • @ikrajmohammad8999
    @ikrajmohammad8999 6 лет назад +1

    Ots good work sir, keep.making more videos on python

  • @rajukumarkhaniya3383
    @rajukumarkhaniya3383 6 лет назад

    Awesome explanations 👍👌👏👏

  • @moazelsawaf2000
    @moazelsawaf2000 6 лет назад +1

    Great topics and very good explanation ❤

  • @kapilsingh7232
    @kapilsingh7232 3 года назад +2

    How we are getting the sorted values as we are not returning values from sort function?

  • @giuseppepala8668
    @giuseppepala8668 5 лет назад +2

    I've found more elegant to substitute lines 6, 7 and 8 with
    list[j], list[j + 1] = list[j + 1], list[j]
    (i've learned that from my favourite Python on-line teacher 😉)

  • @mrfiinesse42
    @mrfiinesse42 4 года назад

    print(sorted(nums)) works just fine

  • @wulf1046
    @wulf1046 3 года назад

    This is perfect thank you

  • @bharathvaj2760
    @bharathvaj2760 4 года назад +3

    5:14 sir we are going from 5 to 0 right?

  • @ahnafrahman3861
    @ahnafrahman3861 4 года назад

    I absolutely love this dude idek why

  • @sahilbisht3661
    @sahilbisht3661 4 года назад

    sir you are great !!

  • @aakarshjain7026
    @aakarshjain7026 6 лет назад +3

    Can you give tutorial of c++ for beginners

  • @makhus8337
    @makhus8337 5 лет назад

    array = [13,147,5,80]
    size = len(array)
    for i in range(0,size):
    for j in range(i+1,size):
    if array[j] < array[i]:
    min = array[j]
    array[j] = array[i]
    array[i] = min
    print(array)

  • @balajiverma.sc-arn-2536
    @balajiverma.sc-arn-2536 3 года назад +1

    Sir, you are the best teacher, but why do you tell programmers "Aliens"?
    Pls explain

  • @nehalkumar7777
    @nehalkumar7777 6 лет назад +16

    now i know why the swap video was inserted in middle 😁😁😂

  • @rohitmalap5599
    @rohitmalap5599 4 года назад +1

    in the function sort, nums is local variable and is valid only for that particular suite. So how does changes in nums in sort function will reflect in nums outside sort? Could you please explain this?

    • @DeepakKumar-cq6jm
      @DeepakKumar-cq6jm 2 года назад

      Num is passed in sort so we can use it as local variable

  • @arvitech7419
    @arvitech7419 6 лет назад +1

    Sir I have a doubt
    I assumed that
    a=bin(7)
    type(a)
    o/p
    Then I assume
    a=0b111
    type(a)
    o/p =
    How sir both a= bin(7) = 0b111 are equal. But how that is str it is int becz both of the value is 0b111

  • @amrutashinde5971
    @amrutashinde5971 4 года назад

    THANK YOU SO MUCH SIR

  • @sirikilohit2077
    @sirikilohit2077 2 года назад

    In Fact, We don't need to type complex logic:
    for i in range(len(nums)-1,0,-1):
    for j in range(i):
    if nums[j] > nums[j+1]:
    nums[j],nums[j+1] = nums[j+1],nums[j]
    Instead we can type like this:
    for i in range(len(nums)-1,0,-1):
    for j in range(i):
    if nums[j] > nums[j+1]:
    nums[j],nums[j+1] = nums[j+1],nums[j]

  • @marioandresheviacavieres1923
    @marioandresheviacavieres1923 2 года назад

    Thanks a lot senor!

  • @sandeeppareek8941
    @sandeeppareek8941 4 года назад +1

    FOR SORTING IN ASCENDING ORDER
    ls = [7, 3, 3, 6, 5, 9, 2]
    ls.sort()
    print(ls)

  • @hruthik1834
    @hruthik1834 3 года назад

    This can be done through the normal sorting method which u explained in the lists concept

  • @EylulTurksever
    @EylulTurksever 4 года назад

    def sorter(list):
    b = len(list)-1
    is_finished = False
    while not is_finished:
    a = 0
    is_finished = True
    while a < b:
    if list[a] > list[a+1]:
    list[a], list[a+1] = list[a+1], list[a]
    is_finished = False
    a += 1
    b -= 1
    return list

  • @saqulainkhan6717
    @saqulainkhan6717 3 года назад

    Sir do you have live classes for ds in python or notes kindly reply

  • @Hex-Scholar
    @Hex-Scholar Год назад

    Clean 👌

  • @NAVEENKUMAR-ho5tw
    @NAVEENKUMAR-ho5tw 5 лет назад

    def lsearch(a,b):
    m=0
    global i
    for i,j in enumerate(a):
    m=m+1
    if b==j:
    return True
    break
    else:
    return False
    a=[22,33,44,55,66,77,88,99]
    b=66
    l=lsearch(a,b)
    if lsearch(a,b):
    print('found')
    print('position is ', i + 1)
    else:
    print('not found')

  • @telugucinemastudio1222
    @telugucinemastudio1222 3 года назад

    Thanks bro this video is very helpful for me. I am studying engineering Would you suggest some tips to enhance my coding and communication skills.

  • @TheSags007
    @TheSags007 5 лет назад

    Thanks for sharing

  • @piyushvaidya3128
    @piyushvaidya3128 3 года назад +2

    For outer loop can we take range(0,len(nums)-1,1)?

  • @gopalakrishnadoddi4869
    @gopalakrishnadoddi4869 4 года назад

    I will be waiting to our online class

  • @sahilchamp
    @sahilchamp 4 года назад

    You can even do nums[j],nums[j+1] = nums[j+1],nums[j] to swap!

  • @AmazingVideoGaming
    @AmazingVideoGaming 6 лет назад +4

    Plz make a video on pygame. Plz sir🙏🙏🙏

  • @happysharma29
    @happysharma29 5 лет назад +1

    It was amazing

  • @054_ritesh3
    @054_ritesh3 4 года назад

    Awsome

  • @ksanjithrahman6339
    @ksanjithrahman6339 5 лет назад

    it was a n wonderful explanation by you sir,
    I would appreciate you to create more on python like insertion sort etc.

  • @tanyachopra890
    @tanyachopra890 5 лет назад

    Really good

  • @ashwinim4226
    @ashwinim4226 2 года назад

    Super

  • @anuthomas5184
    @anuthomas5184 2 года назад

    I am searching for all the sorting algorithms in java telusko. But it's getting python... Can u provide the Bubble sort link in java. Now I became an addict of telusko java learning. It's really Amazing

    • @Game-nr3sr
      @Game-nr3sr 2 года назад

      check in another YT playlist

  • @batteryjuicy4231
    @batteryjuicy4231 3 года назад +2

    you could also have a variable = 0 at the start of every iteration and inciment it by 1 when you swap, therefore if at the end of an iteration the variable is 0 means the list is sorted and you don't have to try to sort the rest of the already sorted list

  • @sagarr1640
    @sagarr1640 3 года назад

    Yeh.. did it before watching ur code -
    def sort(nums):
    for e in range(len(nums)-1):
    for i in range(len(nums)-1):
    if nums[i]>nums[i+1]:
    temp=nums[i]
    nums[i]=nums[i+1]
    nums[i+1]=temp
    else:
    pass
    nums =[5,3,8,6,7,2]
    sort(nums)
    print(nums)