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

preview_player
Показать описание
Sorting the list using Bubble Sort in Python.
#bubblesort
#python

Check out our courses:

Coupon: TELUSKO10 (10% Discount)

Python Tutorial to learn Python programming with examples

Editing Monitors :

Follow on Facebook:

Subscribe to our other channel:
Telusko Hindi :

Donation:
PayPal Id : navinreddy20
Patreon : navinreddy20
Рекомендации по теме
Комментарии
Автор

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 ]

nikitasharma
Автор

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

shamirroy
Автор

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

shenkuulover
Автор

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]

gchoudhary
Автор

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.

parthbhodia
Автор

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

RebeccaNamiya
Автор

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

glorysonhorace
Автор

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

nellaiappan
Автор

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)

harshaddaingade
Автор

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

batteryjuicy
Автор

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

EritreanGamerOfficial
Автор

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

vishnuvardhanreddy
Автор

sir, pls make a video on insertion sort

sagnikray
Автор

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

jeetsutaria
Автор

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

hamidfarooq
Автор

Great topics and very good explanation ❤

moazelsawaf
Автор

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

xathunalwarrior
Автор

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

jackwan
Автор

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

ikrajmohammad
Автор

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

vipulchauhan