List
List is an ordered , mutable sequencially organized data structure whi allowes duplicates List can allow all the datatypes like
list ,tuple, set, distionary also with normal datatypes
In [65]: list1=[1,3,5,7,8,"aa",{"1":2},{3,2,4},(9,8)]
print(list1)
[1, 3, 5, 7, 8, 'aa', {'1': 2}, {2, 3, 4}, (9, 8)]
List Methods
In [66]: [Link](100)
print(list1)
[Link]([11,22]) # it willjoin two lists and it s=add this list as individ
print(list1)
[Link](2,29)
print(list1)
#print([Link]())
print([Link](1))
print(list1)
print([Link]())
print(list1)
print([Link](4))
print(list1)
[Link](3)
print(list1)
print([Link](1))
print(list1)
[Link]()
print(list1)
#[Link]()
[1, 3, 5, 7, 8, 'aa', {'1': 2}, {2, 3, 4}, (9, 8), 100]
[1, 3, 5, 7, 8, 'aa', {'1': 2}, {2, 3, 4}, (9, 8), 100, 11, 22]
[1, 3, 29, 5, 7, 8, 'aa', {'1': 2}, {2, 3, 4}, (9, 8), 100, 11, 22]
1
[1, 3, 29, 5, 7, 8, 'aa', {'1': 2}, {2, 3, 4}, (9, 8), 100, 11, 22]
22
[1, 3, 29, 5, 7, 8, 'aa', {'1': 2}, {2, 3, 4}, (9, 8), 100, 11]
7
[1, 3, 29, 5, 8, 'aa', {'1': 2}, {2, 3, 4}, (9, 8), 100, 11]
[1, 29, 5, 8, 'aa', {'1': 2}, {2, 3, 4}, (9, 8), 100, 11]
0
[1, 29, 5, 8, 'aa', {'1': 2}, {2, 3, 4}, (9, 8), 100, 11]
[11, 100, (9, 8), {2, 3, 4}, {'1': 2}, 'aa', 8, 5, 29, 1]
In [67]: [Link]()
print(list1)
[]
Tuple
Tuple is an ordered ,immutable sequence that allowes duplicates immutable means we cannot do any manipulations like insert
or delete Tuple can allow all the datatypes like list ,tuple, set, distionary also with normal datatypes
In [68]: Tuple=(1,2,[34,1,45],{78,89},1,{"name":"xyz"},"Rajitha",{"name":"xz"})
Tuple Methods
In [69]: [Link]([34,1,45])
Out[69]: 2
In [70]: [Link](2)
Out[70]: 1
In [71]: [Link]({"name":"xyz"})
Out[71]: 5
In [72]: [Link](1)
Out[72]: 2
In [73]: [Link]({"name":"xyz"})
Out[73]: 1
In [74]: print(Tuple)
(1, 2, [34, 1, 45], {89, 78}, 1, {'name': 'xyz'}, 'Rajitha', {'name': 'xz'})
Set
Set is an unordered , mutable collection of unique values set can allows Tuple and other normal datatypes it won't allow list ,
set , dictiionary to it because they are unhashable types(means those are mutable we can change after creation)
Set Methods
In [75]: Set={4,2,67,92,"Name","Name",1,1,(98,89,98)}
print(Set)
{1, 2, 67, 4, (98, 89, 98), 'Name', 92}
In [76]: [Link]({1,2,3,4}) # it will be used to insert multiple elements at a time
print(Set)
{1, 2, 67, 4, 3, (98, 89, 98), 'Name', 92}
In [77]: [Link](100) # it will insert a new element to the set
print(Set)
{1, 2, 67, 4, 3, 100, (98, 89, 98), 'Name', 92}
In [78]: [Link](2) # it will remove the specified element in remove method
print(Set)
{1, 67, 4, 3, 100, (98, 89, 98), 'Name', 92}
In [79]: set1={98,76.87,"Rajitha",22,(55,44)}
set2= {11,22,"Name","Rajitha",55,44,(1,2)}
print(set1)
print(set2)
{98, 'Rajitha', 22, 76.87, (55, 44)}
{'Rajitha', (1, 2), 22, 55, 'Name', 11, 44}
In [80]: [Link](set2)
Out[80]: {22, 'Rajitha'}
In [81]: [Link](set2)
Out[81]: {(55, 44), 76.87, 98}
In [82]: [Link](set2)
Out[82]: {(1, 2), (55, 44), 11, 22, 44, 55, 76.87, 98, 'Name', 'Rajitha'}
In [83]: set3=[Link]()
set3
Out[83]: {(55, 44), 22, 76.87, 98, 'Rajitha'}
In [84]: [Link]()
set3
Out[84]: set()
In [85]: [Link]()
Out[85]: 98
In [86]: print(set1)
print(set2)
{'Rajitha', 22, 76.87, (55, 44)}
{'Rajitha', (1, 2), 22, 55, 'Name', 11, 44}
In [87]: [Link]("Name")
set2
Out[87]: {(1, 2), 11, 22, 44, 55, 'Rajitha'}
In [88]: set1
Out[88]: {(55, 44), 22, 76.87, 'Rajitha'}
In [89]: [Link]("Name") # If the key is not available in set it will throw key err
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
Cell In[89], line 1
----> 1 [Link]("Name")
KeyError: 'Name'
In [90]: [Link]("Name") # If key is not their in the set also it won't throw error
Dictionary
Dictionary is an unordered, mutable collection of key value pair Dictionary can allows Tuple and other normal datatypes it
won't allow list , set to it because they are unhashable types(means those are mutable we can change after creation)
In [106… Dict= {"Name":"Saanvi","Age":30, "Salary":40000,("Branch","Location"):"Hyderabad
Dictionary Methods
In [107… Dict['Name'] # elements accessing
Out[107… 'Saanvi'
In [108… [Link]('Age') # elements accessing by using function
Out[108… 30
In [109… Dict['Name']="Thanmay" #Updating value for an existing key
In [110… print(Dict)
{'Name': 'Thanmay', 'Age': 30, 'Salary': 40000, ('Branch', 'Location'): 'Hyderaba
d'}
In [111… Dict["Dept"]="IT" # adding new key-value pair to the dictionary
print(Dict)
{'Name': 'Thanmay', 'Age': 30, 'Salary': 40000, ('Branch', 'Location'): 'Hyderaba
d', 'Dept': 'IT'}
In [112… [Link](("Branch","Location")) # it will remove and return that secific key
Dict
Out[112… {'Name': 'Thanmay', 'Age': 30, 'Salary': 40000, 'Dept': 'IT'}
In [113… [Link]() # it will remove and returns last key-value pair in the diction
Out[113… ('Dept', 'IT')
In [114… Dict
Out[114… {'Name': 'Thanmay', 'Age': 30, 'Salary': 40000}
In [115… [Link]() # used to get all the keys available in the dictionary
Out[115… dict_keys(['Name', 'Age', 'Salary'])
In [116… [Link]() # used to get all the values available in the dictionary
Out[116… dict_values(['Thanmay', 30, 40000])
In [117… [Link]() # It will return all the key-value pairs available in the diction
Out[117… dict_items([('Name', 'Thanmay'), ('Age', 30), ('Salary', 40000)])
In [118… Dict_dup=[Link]()
Dict_dup
Out[118… {'Name': 'Thanmay', 'Age': 30, 'Salary': 40000}
In [124… Dict1={"Location":"Hyderabad"}
print("Dict1:",Dict1)
print("Dict:",Dict)
Dict1: {'Location': 'Hyderabad'}
Dict: {'Name': 'Thanmay', 'Age': 30, 'Salary': 40000}
In [125… [Link](Dict) #inserts the specified items to the [Link] specified
print(Dict1)
{'Location': 'Hyderabad', 'Name': 'Thanmay', 'Age': 30, 'Salary': 40000}
In [ ]: [Link]()
Dict