

Sorting the list using Bubble Sort in Python.
#bubblesort
#python
Python Tutorial to learn Python programming with examples
Complete Python Tutorial for Beginners Playlist :
Python Tutorial in Hindi :
Github :-
Editing Monitors :
Check out our website:
Follow Telusko on Twitter:
Follow on Facebook:
Telusko :
Navin Reddy :
Follow Navin Reddy on Instagram:
Subscribe to our other channel:
Navin Reddy :
Telusko Hindi :
Donation:
PayPal Id : navinreddy20
Patreon : navinreddy20
Sir
def sort(nums):
for i in range(len(nums)-1,0,-1):
for j in range(i):
if nums[j]>nums[j+1]:
temp=nums[j]
nums[j]= nums[j+1]
nums[j+1]= temp
nums = [9,1,6,8,7]
print(nums)
Me
nums = [9,1,6,8,7]
print(sorted(nums))
that's it
very helpful sir thank you
a=[6,3,2,5,7,8,67,43,23,56,343]
def sort(a):
for i in range(len(a)-1,0,-1):
for j in range(i):
if a[j]>a[j+1]:
temp=a[j]
a[j]=a[j+1]
a[j+1]=temp
return a
print(sort(a))
Navin sir, you are teaching great! 🙂
we didnot return nums then how the output is coming?
can we swaping like this–
num[j],num[j+1]=num[j+1],num[j]
num=[5,7,4,8,9,2]
def bubblesort(num):
for i in range(len(num)-1,0,-1):
for j in range(i):
if num[j]>num[j+1]:
num[j],num[j+1]=num[j+1],num[j]
bubblesort(num)
print(num)
I absolutely love this dude idek why
damn!!!! you good
I will be waiting to our online class
Sorry, but I got confused in this. Specially the outer loop logic. Can you please elaborate using outer and inner loops.
hey, I'm not alien ok.
Hi Sir,
why this code needs to return ??
def fact(n):
f=1
for i in range(1,n+1):
f=f*i
return f
x=5
res=fact(x)
print(res)
and y bubble sort doesn't need return??
Sir 5:20 "6-1" or "5-1"
I didn't get the logic
Your explanation made me to think all types of solution sir;
I have a logic, here you gooo <3
def sort(nums):
for i in range(len(nums)):
for j in range(i+1,len(nums)):
if nums[j]<nums[i]:
nums[i],nums[j]=nums[j],nums[i]
return nums
sort([1,23,4,545])
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)
Hello everyone, I have a doubt if anyone can please help me with it and answer, I didn't understand the range that we took!, (-1,0,-1)
How would i do this for lists with elements which are made up if both strings and integers? Please help me
Can anyone say why he used the range as range(nums(len)-1,0,-1)…. Why is it from the last? please clear my doubt anyone..
dark mode please
i want to sort a array string like {"Man","cda","zyx"} to {"amn","abc","xyz"} please help me i want it algoritium
why the first for loop cannot be
for i in range(0, len(num)) OR
for i in range(0, len(num)-1) OR
for i in range(len(num)-1, 0)
I use this simple logic-
Please thumbs up if you find this convenient:
.
def bubble(list):
for i in range(len(list)-1):
if list[i]>list[i+1]:
list[i],list[i+1]=list[i+1],list[i]
bubble(list)
else:
pass
list=[88,55,10,0,66,12,99]
bubble(list)
print("final list is",list)
It had been very very useful for my son during lockdown
Thank you sir😊☺️