Python Sets Data Type

5 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€60.30
List Price:  €86.14
You save:  €25.84
£53.04
List Price:  £75.77
You save:  £22.73
CA$98.03
List Price:  CA$140.05
You save:  CA$42.02
A$106.92
List Price:  A$152.75
You save:  A$45.83
S$90.85
List Price:  S$129.79
You save:  S$38.94
HK$544.99
List Price:  HK$778.59
You save:  HK$233.60
CHF 56.33
List Price:  CHF 80.48
You save:  CHF 24.14
NOK kr710.85
List Price:  NOK kr1,015.54
You save:  NOK kr304.69
DKK kr450.35
List Price:  DKK kr643.39
You save:  DKK kr193.03
NZ$122.50
List Price:  NZ$175
You save:  NZ$52.50
د.إ257.03
List Price:  د.إ367.21
You save:  د.إ110.17
৳8,559.74
List Price:  ৳12,228.73
You save:  ৳3,668.98
₹6,295.65
List Price:  ₹8,994.18
You save:  ₹2,698.52
RM289.19
List Price:  RM413.15
You save:  RM123.96
₦101,317.52
List Price:  ₦144,745.52
You save:  ₦43,428
₨19,722.41
List Price:  ₨28,176.09
You save:  ₨8,453.67
฿2,242.47
List Price:  ฿3,203.67
You save:  ฿961.20
₺2,969.39
List Price:  ₺4,242.17
You save:  ₺1,272.77
B$375.97
List Price:  B$537.12
You save:  B$161.15
R1,199.03
List Price:  R1,712.97
You save:  R513.94
Лв117.96
List Price:  Лв168.52
You save:  Лв50.56
₩102,826.96
List Price:  ₩146,901.96
You save:  ₩44,074.99
₪227.79
List Price:  ₪325.43
You save:  ₪97.64
₱4,105.75
List Price:  ₱5,865.61
You save:  ₱1,759.85
¥10,921.04
List Price:  ¥15,602.16
You save:  ¥4,681.11
MX$1,282.06
List Price:  MX$1,831.60
You save:  MX$549.53
QR256.23
List Price:  QR366.07
You save:  QR109.83
P935.64
List Price:  P1,336.69
You save:  P401.04
KSh9,049.70
List Price:  KSh12,928.70
You save:  KSh3,879
E£3,327.20
List Price:  E£4,753.35
You save:  E£1,426.14
ብር10,947.79
List Price:  ብር15,640.38
You save:  ብር4,692.58
Kz63,861.07
List Price:  Kz91,234.01
You save:  Kz27,372.94
CLP$65,069
List Price:  CLP$92,959.70
You save:  CLP$27,890.70
CN¥494.81
List Price:  CN¥706.90
You save:  CN¥212.09
RD$4,379.97
List Price:  RD$6,257.36
You save:  RD$1,877.39
DA9,121.78
List Price:  DA13,031.68
You save:  DA3,909.89
FJ$159.10
List Price:  FJ$227.30
You save:  FJ$68.19
Q537.29
List Price:  Q767.59
You save:  Q230.30
GY$14,666.41
List Price:  GY$20,952.92
You save:  GY$6,286.50
ISK kr8,936.32
List Price:  ISK kr12,766.72
You save:  ISK kr3,830.40
DH648.25
List Price:  DH926.11
You save:  DH277.86
L1,189.30
List Price:  L1,699.08
You save:  L509.77
ден3,715.89
List Price:  ден5,308.64
You save:  ден1,592.75
MOP$562.39
List Price:  MOP$803.45
You save:  MOP$241.06
N$1,197.49
List Price:  N$1,710.78
You save:  N$513.28
C$2,579.75
List Price:  C$3,685.51
You save:  C$1,105.76
रु10,042.16
List Price:  रु14,346.56
You save:  रु4,304.39
S/235.68
List Price:  S/336.70
You save:  S/101.02
K301.26
List Price:  K430.39
You save:  K129.13
SAR262.73
List Price:  SAR375.34
You save:  SAR112.61
ZK1,607.12
List Price:  ZK2,295.99
You save:  ZK688.86
L306.91
List Price:  L438.46
You save:  L131.55
Kč1,457.13
List Price:  Kč2,081.70
You save:  Kč624.57
Ft22,991.55
List Price:  Ft32,846.48
You save:  Ft9,854.93
SEK kr662.13
List Price:  SEK kr945.94
You save:  SEK kr283.81
ARS$101,575.61
List Price:  ARS$145,114.23
You save:  ARS$43,538.62
Bs486.16
List Price:  Bs694.55
You save:  Bs208.38
COP$262,754.84
List Price:  COP$375,380.15
You save:  COP$112,625.30
₡34,521.26
List Price:  ₡49,318.20
You save:  ₡14,796.94
L1,846
List Price:  L2,637.25
You save:  L791.25
₲490,029.39
List Price:  ₲700,071.99
You save:  ₲210,042.60
$U2,748.92
List Price:  $U3,927.20
You save:  $U1,178.27
zł255.76
List Price:  zł365.38
You save:  zł109.62
Already have an account? Log In

Transcript

Hi, in this video we are going to discuss about sets in Python by another unordered unique collection of items and does not have indexing or slicing by unique collection of items, I mean like it cannot have any duplicate values, if we like pass on duplicate values within the set set function or we create a set it would not accept it or actually it will delete the duplicate values and only show unique values. So, it is generally used for mathematical set operations for instance you make union intersection, symmetric difference, etc. We can create set in Python by using curly braces. For example, let's create it. I underscore set Still, and one, comma b comma six, comma two. And let's pass on a duplicate value and see what it gives.

Why to get output cc 123 and six it did not repeat to twice. So it actually deleted the duplicate value and only printed out unique value. We can also create set by using set function for example E equals two set and we get a topple inside it. So, one comma three. Oh my God, my six let's print out a so it created a set. So these are the two ways we can create set.

If you're looking to create an empty set that's a bit tricky because when we go about creating an empty set, for example equals to be create a set of curly braces and not put anything else inside it and let's print out. So and when we check its type, for example. So it outputs a dictionaries, what it what it has done is it recognizes as a instead of empty said it recognized it as dictionary. Now in order to actually create a set an empty set, we can use a equals two Set. And when we type its check its type get do we get the output offset. So in order to create an empty set we generally use set function.

Set does not have indexing or slicing if he like. For example, we already have mindset we put on let's print out. So it is going to give an error. That object does not support indexing. It does not have any indexing. And we can add or update elements within set by using add method said doc In that and then I underscore set so it added four to it.

If we are looking to add multiple elements within the set, we can use update method and inside of update method we can like pipe pass on string integers tupple list or any other set as its argument to that to it. My talk update that's Barcelona double e dot was 6958 string A comma B are just a mistake, it does not take in teacher as its parameter, so just remove that. Let's check out this value. So you see 12345689, A and B. Okay, I hope now you have a better understanding by set. In the next video, we'll be discussing about set operations and built in functions.

Besides we'll be like doing set membership tests as well. So stay tuned. Thank you.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.