-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweek3.py
More file actions
68 lines (48 loc) · 1.51 KB
/
week3.py
File metadata and controls
68 lines (48 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 17 20:27:51 2019
@author: Ashay Fernandes
"""
"""
<q> Write a python progran to do the following:
a) Read a list of elemets. Create a new list having all the elements minus duplicate use functions.use
one line comprehensions to create a new list of even numbers . create another list reversing the elements.
"""
lyst1=[]
for i in range(0,5):
lyst1.append(int(input("enter the list element(numbers)\n")));
lyst2=[]
def deldup(lyst):
for i in lyst1:
if i not in lyst2:
lyst2.append(i)
deldup(lyst1)
print(lyst2)
#using list comprehension to generate a list of even numbers
lyst3=[x for x in lyst1 if x%2==0]
lyst4=[x for x in lyst1]
lyst4.reverse()
print(lyst4)
""" b> Write a python program to count the frequency of words in the given file
"""
fhand=open('text.txt')
x=fhand.read()
lyst5=x.split()
dictionary={}
for i in lyst5:
dictionary[i]=dictionary.get(i,0)+1
for key,value in dictionary.items():
print(key,value)
"""
c> read a list of numbers.use a recursive function to find the maximum of 'n' numbers
"""
n= int(input("enter the size of list" ))
lyst6=[]
for i in range(0,n):
lyst6.append(int(input('enter the number')))
def maximum(lyst,n):
if n==1:
return lyst[0]
else:
return max(lyst[n-1],maximum(lyst,n-1))
maximum(lyst6,len(lyst6))