-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfilter.py
More file actions
54 lines (39 loc) · 1.25 KB
/
filter.py
File metadata and controls
54 lines (39 loc) · 1.25 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
# return all the strings starting with vowels in the given sentence
s = 'apple orange mango grapes'
l = s.split()
def vowel(string):
if string[0].lower() in 'aeiou':
return string
print(list(filter(vowel,s.split())))
###################################################################
# print odd numbers in the range 1-50
l = list(range(1,51))
def odd_(num):
if num%2!=0:
return num
print(list(filter(odd_,l)))
######################################################################
# return a list of string with odd length
l = ["gmail", "google", "instagram", "facebook", "yahoo"]
def odd_(string):
if len(string)%2==0:
return string
print(list(filter(odd_,l)))
########################################################################
# return only +ve value in the list
l = [1, -2, -3, 4 , 5, 6]
def pos(num):
if num<0:
return num
print(list(filter(pos,l)))
#######################################################################
# print prime numbers from 1-50
l = list(range(1,51))
def prime(num):
if num>1:
for i in range(2,num):
if num%i==0:
break
else:
return num
print(list(filter(prime,l)))