Python Tricks: How to Find the Most Common Elements in a List

preview_player
Показать описание

Enroll for exercises, tutorials, courses, and projects...

Enroll in Learn Python™ course

==================================================
Connect With Me!

Snapchat ► Rafeh1
Рекомендации по теме
Комментарии
Автор

THIS IS WHAT I DID.


my_groceries = ['apple', 'banana', 'banana', 'orange', 'banana', 'apple', 'beet', 'carrot', 'ginger', 'kale', 'ginger', 'ginger', 'kale', 'ginger']
Final_List = []
DICT = {}
x=0

for element in my_groceries:
if element in DICT:
DICT[element]+=1
else:
DICT[element]=1

for item in DICT:
Final_List.append((item, DICT[item]))

while x<len(Final_List):

for product in range(0, len(Final_List)-1):
if Final_List[product][1] > Final_List[product+1][1]:
pass
else:
temp = Final_List[product]
Final_List[product] = Final_List[product+1]
Final_List[product+1] = temp
x += 1

print(Final_List)

shreshthkaushik
Автор

Brother you make programming look easy and fun. Your channel helped me a lot to learn python. Thank you.

veerpalsingh
Автор

hi kazi i am from algeria and i started learning python but i am not sure that i can find a job here in algeria so can i work from here as a freelancer or should i just quite learning it to not waste the time answer me please

amon-rawalid
Автор

How to determine how much time just a particular word is used in a sentence, if I don't want to know the times for all of the words used in a whole sentence.. Please help me out for that!

souvikghosh
Автор

Wow, that was an easy trick that I didn't know;instead of writing while loop and add them.
This is really helpful. Thank you

bhavikakapadia
Автор

After long time a video I know your bzy your with profitable program Good luck

mnmnaveed
Автор

Which software is best for beginer to learn python ?

sam_block
Автор

I would suggest the name of this series is (Python Explorer)

cancerpml
Автор

In the case of object(string) type pandas.series, .value_counts() would do the same but it gives out a dataframe which respect to each class within the category but this will save a lot of time. Thanks Qazi :D

shhivram
Автор

Can I register to your platform when I have the money.

canicemichael
Автор

Hey qazi, I am not able to find idle for windows and I don't know to use pycharm.

lokeshsolanki
Автор

if you lazy thinking the list is long, take this :
my_groceries = ['apple', 'banana', 'banana', 'orange', 'banana', 'apple', 'beet', 'carrot', 'ginger', 'kale', 'ginger', 'ginger', 'ginger', 'kale', 'ginger']

marinosterbah