6 Exp Python
6 Exp Python
Experiment No. 6
Roll No 55
i) WAP to find the most frequent words in a text read from a file.
Source Code:
def find_most_frequent_words(file_path):
with open("a1.txt", 'r') as file:
text = file.read().lower()
words = re.findall(r'\b\w+\b', text)
word_count = Counter(words)
for word, count in word_count.most_common(10):
print(f"{word}: {count}")
file_path = "a1.txt"
find_most_frequent_words(file_path)
import pickle
def read_from_file(filename):
with open(filename, 'rb') as file:
data = pickle.load(file)
return data
data = {
'name': 'Ashish prajapati',
'age': 23,
'city': 'Thane'
}
filename = 'data.pkl'
write_to_file(filename, data)
loaded_data = read_from_file(filename)
print("\nLoaded data:")
print(loaded_data)
def create_smiley(self):
self.create_oval(50, 50, 250, 250, fill="yellow", outline="yellow")
self.create_oval(100, 100, 130, 130, fill="black", outline="black")
self.create_oval(170, 100, 200, 130, fill="black", outline="black")
self.create_arc(100, 130, 200, 190, start=0, extent=-180, fill="black", style=tk.ARC)
if __name__ == "__main__":
root = tk.Tk()
root.title("Smiley Face")
smiley_canvas = SmileyCanvas(root)
smiley_canvas.pack(fill="both", expand=True)
root.geometry("300x300")
root.mainloop()
Conclusion: We successfully implement basic python programs to demonstrate File handling and
GUI using Tkinter.