# How To Use Sets in Python (Python Tutorial #13)

///How To Use Sets in Python (Python Tutorial #13)

## How To Use Sets in Python (Python Tutorial #13)

Python tutorial – how to use sets!
This entire series in a playlist:
Also, find me on Instagram:

source

By |2019-12-04T00:23:04+00:00December 4th, 2019|Python Video Tutorials|23 Comments

1. eli eli December 4, 2019 at 12:23 am - Reply

def sum(x):
y=0
x=x.split()
x=set(x)
for i in x:
y=int(i)+y
print(y)

n=input("enter some number with space: ")
sum(n)

2. Omar Shafi December 4, 2019 at 12:23 am - Reply

Fantastic teacher. I have struggled with coding for 4 years, and you've really helped a lot. Such a legend, thank you so much.

3. Luminescence December 4, 2019 at 12:23 am - Reply

given_list = [1, 3, 4, 1, 3]

new_set = set()
new_list = list ()
total = 0
for x in given_list:
for x in new_set:
new_list.append(x)
total += x
print(new_list)
print(total)

4. Genki Penguin December 4, 2019 at 12:23 am - Reply

Hi ive been watching your python series and I really learned a lot in your tutorial videos. Your explanation makes it easy to understand. I wonder if you have a series for Python NLTK.

5. Marcel Del Castillo December 4, 2019 at 12:23 am - Reply

#hi this is my solution regards from bolivia and thank you
g=set()

sum=0

counter=0

z=[1,3,4,1,3]

print(z)

for y in z:

print(g)

for y in g:

sum=sum+y

counter+=1

print(sum)

print(counter)

6. Goncalo Duarte December 4, 2019 at 12:23 am - Reply

Lets see if it works …ย

and it does! ๐ย

– Cheers for the good work mate!

7. Todd Henderson December 4, 2019 at 12:23 am - Reply

I used a for loop for this question:

new_set2 = set()

for x in given_list3:

total = 0

for x in new_set2:

total = total + x

print(total)

8. Omar Nael December 4, 2019 at 12:23 am - Reply

5:30 [ in Jupyter notebook 5.7.7 the set makes the right order in which you add things now]

9. Martin Kaspar December 4, 2019 at 12:23 am - Reply

release this as a jn plz

10. Abdur Rahman December 4, 2019 at 12:23 am - Reply

please continue the series from this beginner level to advanced level and make projects tutorial.ur vids are awesome.u talk so well

11. Angus Clark December 4, 2019 at 12:23 am - Reply

Why apple and banana though lol

12. ้ฟๅ December 4, 2019 at 12:23 am - Reply

#list = [1,3,4,1,3]
#find unique numbers in "list" to sum up

list = [1,3,4,1,3]
b = set()
for x in list:
k = sum(b)
print(k)

13. Nikita Sinha December 4, 2019 at 12:23 am - Reply

Thank you so much sir๐

14. kaviya k_pop December 4, 2019 at 12:23 am - Reply

Hi… First of all, many thanks for teachin us to help learn a new lang. Am from India (Tamil_Nadu) Please dont stop ๐.. Pls continue wit ur python tutorial. I am a non programmer and I am learning python by watchin ur tutorials. I dint find any of the other online tutorials appealing. Humble request…please Cont wit ur tutorial๐ ๐ ๐

15. Nishant Choudhary December 4, 2019 at 12:23 am - Reply

Sir, we can simply put this code also :
J = set(g)
sum(j)

So why you always do this for adding something in a set ( just highlighting j = set(g) ) :

set_1 = set()
for x in g:
print(set_1)

16. dante December 4, 2019 at 12:23 am - Reply

is the series over?

17. mohamed gamal December 4, 2019 at 12:23 am - Reply

awesome

18. Stephan van der Hulst December 4, 2019 at 12:23 am - Reply

FYI you can just cast a set into a list now, no more for-loop needed: new_list = list(new_set)

For the second part of the video:
given_list2=[1,3,4,1,3]

print(sum(set(given_list2)))

Again, no for-loop needed.

19. Urstonerfriend December 4, 2019 at 12:23 am - Reply

I did:
list = [1,3,4,1,3]
strip = set(list)
total = 0

for x in strip:
temp = x
total = total + temp

print(total)

20. Thomas Cao December 4, 2019 at 12:23 am - Reply

Will there be more episodes? Learning from this channel is great

I think you could have talked about type casting aswell as it would be much faster.
A = [1,2,3,2,3,2,1] # set
B=set(A) # type casts list A into set
A=list(B) # type casts set B into list"

22. abood harb December 4, 2019 at 12:23 am - Reply

it would be better if you gave the solution in the next video

23. Nithin Krishna December 4, 2019 at 12:23 am - Reply

I have question that ,do you finish the full course of python or not…..
If not please continue the series….
And i,am big fan of your videos that, i have started learning python from your videos…!!