Professional Documents
Culture Documents
❖ The tuple data type is almost identical to the list data type
❖ Don’t intend for that sequence of values to change, contents don’t change
Lists and Dictionaries are MUTABLE objects, can insert, delete (can modify
structure)
❖ Unlike indexes for lists, indexes for dictionaries can use many different data
types, not just integers.
❖ Indexes for dictionaries are called keys, and a key with its associated value
is called a key-value pair
❖ Dictionaries can still use integer values as keys, just like lists use integers for
indexes, but they do not have to start at 0 and can be any number.
Repititions
The keys(), values(), and items() Methods
❖ Three dictionary methods that will return list-like values of the dictionary’s
keys, values, or both keys and values: keys(), values(), and items()
❖ can also use the multiple assignment trick in a for loop to assign the key
and value to separate variables
>>> ls=[12,34,56]
>>> tuple(ls)
>>> list(t)
>>> d={23:4,56:7}
>>> tuple(d)
(56, 23)
>>> list(d)
[56, 23]
s={12,'iglobal',56.7,'123'}
>>> type(s)
<class 'set'>
>>> s[0]
s[0]
>>> for i in s:
print(i)
56.7
iglobal
123
12
>>> dir(set)
>>> s={12,56.7,8,12,56.7}
>>> s
{56.7, 8, 12}
>>> s={1,2,3,4}
>>> s1={3,4,5,6}
>>> s.intersection(s1)
{3, 4}
>>> s={1,2,3,4,5,6}
>>> s1={3,4,5}
>>> s1.subset(s)
s1.subset(s)
>>> s1.issubset(s)
True
>>> s.issuperset(s1)
True
>>> s.remove(6)
>>> s
{1, 2, 3, 4, 5}
>>> s={'java','c++','python'}
>>> s.union(s1)
>>> ls=[1,2,3,2,5,1]
>>> set(ls)
{1, 2, 3, 5}
>>> list(set(ls))
[1, 2, 3, 5]