Remove Duplicates From Python List | Using Sets |

Опубликовано: 17 Июль 2021
на канале: OsChannel
593
20

This #Shorts video contains a python3 trick to remove duplicates from a list.

----
#Our list is:
my_list = [ 1, 1, 2, 2, 3, 4, 5 ]

Python sets do not support duplicate items, so we convert the list into a set
my_list = set(my_list)

Now if you check the contents of my_list, it's a set represented by curly braces '{' '}'
{ 1, 2, 3, 4, 5}

and finally we convert back the set into a list:
my_list = list(my_list)

which gives us
[ 1, 2, 3, 4, 5 ]
----
This can also done using one line of code:
my_list = [ 1, 1, 2, 2, 3, 4, 5 ]
my_list = list(set(my_list))
----


PLAYLIST WITH SIMILAR VIDEOS:
   • Python #Shorts by OsChannel  

Subscribe to OsChannel for more such tricks -
CHANNEL LINK:
   / oschanneldotcom  

LINK TO MY WEBSITE:
https://oschannel.com


На этой странице сайта вы можете посмотреть видео онлайн Remove Duplicates From Python List | Using Sets | длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь OsChannel 17 Июль 2021, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 593 раз и оно понравилось 20 зрителям. Приятного просмотра!