Skip to main content

/docs/images/banner.jpg

Python

Lists, Tuples & Dictionaries

Write python programs to understand Tuples, Dictionaries, Arrays.


# Tuples
tup = (1, 2, 3, 4, 5)
print(tup)

# Dictionaries
dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}
print(dict)

# Arrays
arr = [1, 2, 3, 4, 5]

# Operations on Tuples
print(tup[0])
print(tup[1:3])
print(tup + (6, 7, 8))
print(tup * 2)
print(len(tup))
print(max(tup))
print(min(tup))

# Operations on Dictionaries
print(dict['Name'])
print(dict['Age'])
print(dict['Class'])
print(dict.keys())
print(dict.values())

# Operations on Arrays
print(arr[0])
print(arr[1:3])
print(arr + [6, 7, 8])
print(arr * 2)
print(len(arr))
print(max(arr))
print(min(arr))
print(arr.pop())
print(arr)
arr.remove(4)
print(arr)
arr.insert(0, 0)
print(arr)
arr.sort()
print("sorted array: ",arr)
arr.reverse()
print(arr)
print(arr.count(1))
print(arr.index(1))
ar1=arr.copy()
print("copy: ",ar1)
arr.clear()
print("cleared array: ",arr)
arr.extend([1, 2, 3])
print(arr)
arr.append(1)
print(arr)