- Notifications
You must be signed in to change notification settings - Fork 152
/
Copy pathpractice.py
62 lines (46 loc) · 1.23 KB
/
practice.py
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
defmost_common(str_a, str_b):
returnset(str_a) &set(str_b)
result=most_common("NAINA", "RENNE")
print(result) # {N}
defget_freq(str):
freq_dict= {}
forcharinstr.split():
ifcharnotinfreq_dict.keys():
freq_dict[char] =1
else:
freq_dict[char] +=1
returnfreq_dict
result=get_freq("Amogh loves to eat apple and mango. His sister also loves eating apple and mango")
print(result)
# {'Amogh': 1, 'loves': 2, 'to': 1, 'eat': 1, 'apple': 2, 'and': 2, 'mango.': 1, 'His': 1, 'sister': 1, 'also': 1, 'eating': 1, 'mango': 1}
defis_prime(num):
flag=1
foriinrange(2, num//2):
ifnum%i==0:
flag=0
break
ifflag==0:
print(f"{num} is not prime...")
else:
print(f"{num} is prime...")
is_prime(7919) # 7919 is prime
deffibo_iter(n_terms):
first, second=0, 1
foriinrange(0, n_terms):
ifi<=1:
result=i
else:
result=first+second
first=second
second=result
print(result, end=' ')
fibo_iter(5) # 0 1 1 2 3
deffibo_recur(n):
ifn==0:
return0
elifn==1:
return1
else:
returnfibo_recur(n-1) +fibo_recur(n-2)
foriinrange(0, 10):
print(fibo_recur(i), end=' ') # 0 1 1 2 3 5 8 13 21 34