PYTHON 7 output,
PYTHON 7 output,
item_counts = Counter(my_tuple)
repeated_items = [item for item, count in item_counts.items() if count > 1]
print("Repeated items:", repeated_items) # Output: Repeated items: [1, 2, 3]
6) Print the number in words for Example: 1234 => One Two Three Four
def number_to_words(n):
num_dict = {
0: "Zero", 1: "One", 2: "Two", 3: "Three", 4: "Four",
5: "Five", 6: "Six", 7: "Seven", 8: "Eight", 9: "Nine"
}
number = 1234
print(number_to_words(number)) # Output: One Two Three Four
PRACTICAL NO 10
3) Write a Python program to create a set, add member(s) in a set and remove one item from set.
# Create a set
my_set = {1, 2, 3, 4}
# Add members to the set
my_set.add(5)
my_set.update([6, 7]) # Adding multiple elements
print("Set after adding elements:", my_set) # Output: {1, 2, 3, 4, 5, 6, 7}
# Remove an item from the set
my_set.remove(3) # Removes 3 from the set
print("Set after removing an element:", my_set) # Output: {1, 2, 4, 5, 6, 7}
4) Write a Python program to find maximum and the minimum value in a set.
my_set = {10, 20, 5, 40, 30}
# Find the maximum and minimum values
max_value = max(my_set)
min_value = min(my_set)
print("Maximum value:", max_value) # Output: Maximum value: 40
print("Minimum value:", min_value) # Output: Minimum value: 5
5) Write a Python program to find the length of a set.
my_set = {10, 20, 30, 40}
2. Write a Python script to concatenate following dictionaries to create a new one. Sample Dictionary:
diel (1:10, 2:20) dic23:30, 4:40} dic35:50,6:60}
# Sample dictionaries
d1 = {1: 10, 2: 20}
d2 = {3: 30, 4: 40}
d3 = {5: 50, 6: 60}
# Concatenate dictionaries
merged_dict = {**d1, **d2, **d3}
# Intersection of sets
intersection = set1 & set2
print(f"Intersection: {intersection}")
# Union of sets
union = set1 | set2
print(f"Union: {union}")
# Clear a set
set1.clear()
print(f"Set1 after clearing: {set1}")
4) Write a Python program to combine two dictionary adding values for common keys. d1= {'a': 100, 'b':
200, 'c':300} d2= {'a': 300, 'b': 200, 'd':400}
d1 = {'a': 100, 'b': 200, 'c': 300}
d2 = {'a': 300, 'b': 200, 'd': 400}
# Sort the dictionary by value in descending order and get the top 3 highest values
highest_three = sorted(d.items(), key=lambda x: x[1], reverse=True)[:3]
print(f"Highest 3 Values: {highest_three}")
6) What is the output of the following program?
def print_animals(*animals):
for animal in animals:
print(animal)