Python Programs
Python Programs
Input:
another_list = [6, 0, 4, 1]
my_list.append(another_list)
print(my_list)
Output:
Input:
Tuple1 = ()
print(Tuple1)
print(Tuple1)
list1 = [1, 2, 4, 5, 6]
print("\nTuple using List: ")
print(tuple(list1))
Tuple1 = tuple('Geeks')
print(Tuple1)
Output:
Input:
def last(n):
return n[m]
def sort(tuples):
print("Sorted:"),
print(sort(a))
Output:
Sorted: [(23, 45, 20), (89, 40, 23), (25, 44, 39)]
14. Tuple program to print half in one line and another half in another line
Input:
def print_half_tuple(tup):
midpoint = len(tup) // 2
print(*tup[:midpoint])
print(*tup[midpoint:])
Output:
12345
6 7 8 9 10
Input:
phone_dictionary = {
"Alice": "123-456-7890",
"Bob": "987-654-3210",
"Carol": "456-789-0123"
}
phone_number = input("Enter the phone number: ")
if phone_number in phone_dictionary:
name = phone_dictionary[phone_number]
print("The name associated with the phone number {} is
{}".format(phone_number, name))
else:
print("The phone number {} is not found in the phone
dictionary".format(phone_number))
Output:
Input:
return(dict2.update(dict1))
print(Merge(dict1, dict2))
print(dict2)
Output:
None
Input:
def display_dictionary_elements(my_dict):
for key, value in my_dict.items():
print(f"{key}: {value}")
my_dict = {"name": "John", "age": 30, "city": "New York"}
display_dictionary_elements(my_dict)
Output:
name: John
age: 30