0% found this document useful (0 votes)
2 views4 pages

Exp6 02

The document outlines an experiment on Sets and Dictionaries in Python, demonstrating various operations such as creation, type checking, adding elements, copying, clearing, and performing set operations like difference and intersection. It also introduces dictionaries, showcasing how to create them, access items, and retrieve keys. The experiment includes code snippets and their outputs to illustrate the concepts effectively.

Uploaded by

anya jadhav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Exp6 02

The document outlines an experiment on Sets and Dictionaries in Python, demonstrating various operations such as creation, type checking, adding elements, copying, clearing, and performing set operations like difference and intersection. It also introduces dictionaries, showcasing how to create them, access items, and retrieve keys. The experiment includes code snippets and their outputs to illustrate the concepts effectively.

Uploaded by

anya jadhav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Experiment NO: 06

Experiment Name : Set And Dictionary


Name : Rushi Rade
class : CSE (SY-B)
Roll No: 02

Set
a={1,2,3}
print(type(a))

<class 'set'>

a={1,True}
print(type(a))

<class 'set'>

print(a)

{1}

b={1,1,2,3,3}
print(b)

{1, 2, 3}

c={False,0}
print(c)

{False}

c={0,False}
print(c)

{0}

a={1,2,3,4,5,'Rushi'}
a[2]

----------------------------------------------------------------------
-----
TypeError Traceback (most recent call
last)
Cell In[16], line 2
1 a={1,2,3,4,5,'Rushi'}
----> 2 a[2]

TypeError: 'set' object is not subscriptable

a.add('hari')
print(a)

{1, 2, 3, 4, 5, 'hari', 'Rushi'}

a1=a.copy()
print(a1)

{1, 2, 3, 4, 5, 'hari', 'Rushi'}

a1.clear()
print(a1)

set()

a1=a.copy()
print(a1)

{1, 2, 3, 4, 5, 'hari', 'Rushi'}

b={5,6,7,8,'Ram'}
print(b)

{5, 6, 7, 8, 'Ram'}

a.difference(b)

{1, 2, 3, 4, 'Rushi', 'hari'}

b.intersection(a)
print(a)

{1, 2, 3, 4, 5, 'hari', 'Rushi'}

b.issubset(a)

False

a={1, 2, 3, 4, 5, 'Rushi', 'hari'}


print(a)

{1, 2, 3, 4, 5, 'hari', 'Rushi'}

a={1,2,3}
print(type(a))
a={1,True}
print(type(a))
print(a)
b={1,1,2,3,3}
print(b)
c={False,0}
print(c)
d={1,False}
print(d)
a={1,2,3,4,5,'Rushi'}
print(a)
a.add('hari')
print('Add :',a)
a1=a.copy()
print('copy :',a1)
b={5,6,7,8,'Ram'}
print(b)
print('Difference Function :')
print(a.difference(b))
print('Intersection Function :')
print(b.intersection(a))
print(a)
print('Subset :',b.issubset(a))
a1.clear()
print('Clear Function',a1)

<class 'set'>
<class 'set'>
{1}
{1, 2, 3}
{False}
{False, 1}
{1, 2, 3, 4, 5, 'Rushi'}
Add : {1, 2, 3, 4, 5, 'hari', 'Rushi'}
copy : {1, 2, 3, 4, 5, 'hari', 'Rushi'}
{5, 6, 7, 8, 'Ram'}
Difference Function :
{1, 2, 3, 4, 'hari', 'Rushi'}
Intersection Function :
{5}
{1, 2, 3, 4, 5, 'hari', 'Rushi'}
Subset : False
Clear Function set()

Dictionary
a={}
print(type(a))

<class 'dict'>

a=set({})
print(a)
set()

a={1:'Rushi',2:'Pruthviraj'}
print(type(a))

<class 'dict'>

b={'MI':'5 Trophy','CSK':'5 Trophy','RCB':'0 Trophy'}


print(b)

{'MI': '5 Trophy', 'CSK': '5 Trophy', 'RCB': '0 Trophy'}

print(a.items())

dict_items([(1, 'Rushi'), (2, 'Pruthviraj')])

print(b.items())

dict_items([('MI', '5 Trophy'), ('CSK', '5 Trophy'), ('RCB', '0


Trophy')])

print(a.keys())

dict_keys([1, 2])

print(b.keys())

dict_keys(['MI', 'CSK', 'RCB'])

You might also like