Practical No 8
keys = ['apple', 'banana', 'cherry']
values = [1, 2, 3]
# Map the lists into a dictionary
mapped_dict = dict(zip(keys, values))
# Print the resulting dictionary
print(mapped_dict)
Practical No 9
def count_word_frequency(text):
text = text.lower()
words = text.split()
word_freq = {}
for word in words:
clean_word = ''.join(char for char in word if char.isalnum())
if clean_word:
word_freq[clean_word] = word_freq.get(clean_word, 0) + 1
return word_freq
input_string = "Hello world! Hello, OpenAI. OpenAI creates, OpenAI innovates."
frequency = count_word_frequency(input_string)
print(frequency)
Practical No 10
def recursive_length(lst):
if not lst:
return 0
else:
return 1 + recursive_length(lst[1:])
my_list = [10, 20, 30, 40, 50]
print("Length of the list:", recursive_length(my_list))
Practical No 11
import math
class Sphere:
def _init_(self, radius):
self.radius = radius
def diameter(self):
return 2 * self.radius
def circumference(self):
return 2 * math.pi * self.radius
def volume(self):
return (4/3) * math.pi * (self.radius ** 3)
radius = 5
sphere = Sphere(radius)
print("Diameter: {sphere.diameter()}")
print("Circumference: {sphere.circumference()}")
print("Volume: {sphere.volume()}")