Vinay Python Notes
Vinay Python Notes
Vinay Python Notes
Features of python:
1)Functional programming language: we can write programs by
using functions
Boolean: Boolean data type have only two True and False
Default value of bool is False.
a=False
print(a)
print(type(a))
by default python consider True as 1 and False
False has 0.
Complex:complex data type will have two parts.
1)real part
2)imaginary part
a=3+4j
print(a)
print(type(a)
1)string:
• string is declared by using single coats(‘ ’)
double coats(“ “),triple coats(‘’’ ‘’’).
• if we declare a single line string we use single coats and
double coats and we declare multiline string we use
triple coats.
• String is orderd data type it support indexing.
• String is immutable data type it can’t be modified.
2)List:
• list is declared by using square brackets([]).
• List is ordered data type it support’s indexing.
• List is mutable data type it can be modified.
• It allows duplicate.
• List is both homoginus and heteroginus
Homoginus means having similar
data([1,2,3,4,5])and heteroginus means having
different data([1,2.3,True,3+4j]).
3)Tuple:
• Tuple is declared by using round brackets().
• Tuple is ordered data type it support indexing.
• It is immutable data type it can’t be modified but
mutable data types in tuple can be modifies.
• It allows duplicates
• If we declare single value in tuple comma(,) is
mandatory
• It is both homogenus and heterogenus
4)set:
• Set is declared by using curlie brackets{} but
empty set is declared by using set() function.
• Set is unordered data type it doesn’t support
indexing.
• Set is mutable data type it can be modified.
• It does not allow duplicates.
• It is both homogenus and heterogenus but it
allows only immutable data type.
5)dictionary:
• dictionary is declared by using curlie brackets
{}and elements are in the form of key value pair.
• It ordered data type but it doesn’t support
indexing
• It is mutable data type it can be modified.
• Duplicate keys are not allowed if we add
duplicate keys old value replaced with new value
where as duplicate values are allowed
• Only immutable keys are allowed but values can
be both mutable and immutable.
Operators:
1.arithamatic operators(+, - , * , % , **, /, //).
2. Comparision operators(>, <, >=, <=, ==, !=).
3. Assignment operators(=,+=,-=,*=,/=,%=,//=).
4. Betwise operators(&,|,^,~,<<,>>).
5. Logical operators(and,or).
6. Membership operators(in,not in)
7. Identity operators(is,is not)
8. Terinary operators(it means we should write if and else
in single line).
op: VINAY
Lower():this method is used to convert all upper case
charecters to lower case charecters.
Example: n='VINAY'
print(n.lower())
op: vinay
swapcase: this method is used to convert all uppercase charecters to lo
wer case and lower case charecters to upper case.
Example:
n='vinayVicky'
print(n.swapcase())
op: VINAYvicky
title: this method is used to convert every word of first character into
uppercase.
Example: i='hai vinay how are you'
print(i.title())
Op: Hai Vinay How Are You
Capitalize: this method is used to convert first letter of a string into upperc
ase remaining all lower case.
Example: j='python developer'
print(j.capitalize())
op: Python developer
index:
• it returns index position of first occurrence of a substring
• if substring is not avalible then it throughs value error.
Example: h='hai good morning'
print(h.index('o'))
op:5
rindex:
• it returns index position of last occurrence of a substring
• if substring is not avalible then it throughs value error.
Example: h='hai good morning'
print(h.rindex('o'))
op:8
find:
• it returns index position of first occurrence of a substring
• if substring is not avalible then it will not through any error it returns
-1
Example:
h='hai good morning'
print(h.find('x'))
op:-1
rfind:
• it returns index position of last occurrence of a substring
• if substring is not avalible then it will not through any error it returns
-1
Example:
h='hai good morning'
print(h.find('x'))
op:-1
count:
• it returns no.of times substring occurred in string.
• If substring is not avalible then it returns 0
•
Example:
h='engineering'
print(h.count('e'))
op:3
replace: this method is used to replace one substring with another substri
ng
Example: a='vinay'
print(a.replace('v','s'))
op:sinay
split:
• this method is used to convert string into list.
• Providing argument is not given by default it takes space as a delimator
Example: n='vinay is a python developer'
print(n.split())
op:['vinay', 'is', 'a', 'python', 'developer']
format: this method is used for variable substation in a specified place holder.
Example: i='vinay'
j=20
print(f'{i} is {j} years old')
op: vinay is 20 years old
slicing: slicing is a feature to access part of sequence from string list tuple.
Example:
x='vinay compleated masters'
print(x[:]) op: vinay completed masters
print(x[0:]) op: vinay completed masters
print(x[2:5]) op: nay
print(x[::2]) op: vnycmlae atr
print(x[-1:-6:-1]) op: srets
print(x[-1:-6:-2]) op: ses
print(x[::-1]) op: sretsam detaelpmoc yaniv
append:
• this method is used to add one value at time
• value is added at end of the list
Example: l=[12,13,14,15]
l.append(16)
print(l)
Op: [12, 13, 14, 15, 16]
Insert:
• this method is used to add one value at a time.
• Value is added at given index position.
Example: l=[11,13,14,15]
l.insert(1,12)
print(l)
op:[11, 12, 13, 14, 15]
extend:
• this method is used to add multiple values at time.
• It takes only one argument which is of collection data type.
Remove:
• It is used to remove values into the list.
• If value occurs more than once then it returns first occurrence of value.
• If value is not available then it throughs value error.
Example: x=[11,12,13,14,15,12]
x.remove(12)
print(x)
op:[11, 13, 14, 15, 12]
pop:
• It takes index as an argument.
• It returns removed value.
• Index is not given by default it takes index as -1.
Example: a=[20,30,40,50]
x=a.pop(1)
n=a.pop()
print(x) op:30
print(n) op:50
print(a) op:[20,40
clear: this method is used to remove all values into the list.
Example: x=[1,2,3,4,5,6]
x.clear()
print(x) op: [ ]
index:
Example: n=[22,33,44,55]
print(n.index(33))
op:1
count:
Example: n=[22,33,44,55,22,33,22]
print(n.count(22))
op:3
sort:
• it works only on homoginus of list.
• it is used to arrange the data from ascending and descending.
Example: # ascending order # descinding order
x=[4,3,5,6,2,7,1,8,9] x=[4,3,5,6,2,7,1,8,9]
x.sort() x.sort(reverse=True)
print(x) print(x)
op:[1, 2, 3, 4, 5, 6, 7, 8, 9] [9, 8, 7, 6, 5, 4, 3, 2, 1]
n={22,33,44}
n.update('vinay',[1,33,44,1])
print(n)
op:{'v', 33, 1, 'a', 44, 'y', 'n', 'i', 22}
op: keyError
op
Discard: this method is used to remove values in set if value
is not avalible in set it will not through any error.
Example: s={1,2.0,'vinay',(22,33)}
s.remove('vinay') s={1,2.0,'vinay',(22,33)}
print(s)
s.remove(5)
op:{1, 2.0, (22, 33)}
print(s)
op: {1,2.0,'vinay',(22,33)}
op
pop:
• it returns the removed value and it will not accept any argument.
• it removes the random value from set.
Example: x={1,2.0,'vinay',(22,33)}
x.pop()
print(x)
op:{2.0, (22, 33), 'vinay'}
Example: n={}
n['a']=10
n['b']=20
n[1]=20
n[(22,33)]=30
n[2.0]=40
n['a']=20
print(n)
op:{'a': 20, 'b': 20, 1: 20, (22, 33): 30, 2.0: 40}
update: this method is used to add multiple key value pair to the dictionary.
Example: x={'a':10,'b':20}
y={'c':30,'d':40}
x.update(y)
print(x)
print(y)
op:{'a': 10, 'b': 20, 'c': 30, 'd': 40}
op:{'c': 30, 'd': 40}
remove key value pair into the dictionary:
pop:
• pop takes key as an argument
• it returns the value of key provided,if key is not in dictionary it throu
ghs key error.
Example: n={'a':10,'b':20,'c':30}
m=n.pop('a')
print(m)
print(n)
x=n.pop('d')
print(x)op:key error
op:10
op:{'b': 20, 'c': 30}
get:
• get method is used to return the values of given key.
• If key is not in dictionary it default value.
• If default value is not given it returns none.
Example: g={'a':10,'b':20,'c':30,'d':40}
print(g.get('a'))
print(g.get('f',100))
print(g.get('g'))
op:10
op:100
op:None
setdefault:
• it returns the value of given key.
• if key is not in dictionary it returns the default value and update the d
ictionary with key value pair.
Example: s={'a':10,'b':20,'c':30,'d':40}
print(s.setdefault('d'))
print(s.setdefault('f',100))
print(s)
op:40
op:100
op:{'a': 10, 'b': 20, 'c': 30, 'd': 40, 'f': 100}
fromkeys:
• from keys is used to create a dictionary with same values for all given
keys.
• If value is not given then dictionary of keys are updated with None ke
y word.
Example: d={}
x=d.fromkeys('abc',[1,2,3])
print(x)
op:{'a': [1, 2, 3], 'b': [1, 2, 3], 'c': [1, 2, 3]
type casting: convert one data type to another data type it is called typ
e casting. boolean
Int A=10 print(bool(A)) op: true
Int(15.5) op:15
Int(True) op:1 A=0 print(bool(A)) op: False
Int(3+2j) op: type error A=0.0001 print(bool(A)) op: True
Int(11.8) op:11
B=0.1 print(bool(B)) op: True
Int(‘10’) op: 10
Int(’11.8’) op: type error C=0.0 print(bool(c)) op: False
C=3+4j print(bool(C)) op: True
float
float(11) op: 11.0 D=’_’ print(bool(D)) op: True
float(2+4j) op: type error A=[1,2,3,4] print(bool(A)) op: True
float(True) op:1.0
float(’12.5’) op: 12.5 A=[0] print(bool(A)) op: False
float(‘12’) op: 12.0 A=(0) print(bool(A)) op: False
Dictionary to list
y={'a':10,'b':20,'c':30}
print(list(y))
print(len(y))
op:['a', 'b', 'c']
op:3
Dictionary to list
y={'a':10,'b':20,'c':30}
print(set(y))
print(len(y))
op:{'a', 'b', 'c'}
op:3
Else:
• if given condition is false then control goes to else block.
• For else block if block is mandatory.
Elif:
• If previous condition is false then control goes to elif
block.
• For elif block if block is mandatory and else block is not
mandatory.
• For one if block we can write multiple elif blocks.
input method:
• This method is used to take input at run time.
• Input method accept values in the form of string.
X=input(‘enter the value of x’)
Print(type(of(x)) op: str
To convert int
X=int(input(‘enter the value of x’))
Print(type(x)) op: int
Range inbuilt function:
• Range function returns a sequence of numbers starting
from 0 by default and increments one by one and stops
before a specified number.
• Range is work only in list and tuple.
Ex: x=list(range(1,10))
Print(x) op:[1,2,3,4,5,6,7,8,9]
Ex: x=tuple(range(1,10))
Print(x) op:(1,2,3,4,5,6,7,8,9)
Ex: x=list(range(-1,-5,,-1))
Print(x) op:[-1,-2,-3,-4]
Ex: y=list(range(-10,-1,-1))
Print(x) op:[-10,-9,-8,-7,-6,-5,-4,-3,-2]
Loops in python:
In python there are two types of loops are there
1) for ,2)while
1)for loop:
• if we know the iterations then we use for loop.
• Starting point of execution and ending point execution
both has to be same.
• No.of iterations is same as the sequence.
for i in range(1,5):
print(I,end=’ ‘) op:1,2,3,4
for b in range(1,5): for a in range(1,5): for i in range(5):
vinay 1 0
vinay 1
2
vinay 2
3
vinay 3
4
4
n=[22,33,44,55] X={‘a’:10,’b’:20,’c’:30}
X=’vicky’
for i in n: for a in x:
for a in x:
print(i) print(a)
print(a)
op: a
op:
22 b
v
33 c
i
c 44
k 55
X={‘a’:10,’b’:20,’c’:30}
for a in x.values():
print(a)
op:
10
20
30
print(f’ {k}={v}’)
(a,10)
(b,20)
(c,30)
2)while loop:
• If we don’t know the iterations then we use while loop.
• If condition is true then control enters the loop
otherwise control goes outside the loop.
n=1 n=5 n=1
1 5 vinay
2 4 vinay
3 3 vinay
4 2 vinay
Control statements:
In python there are 3 control statements are there.
1)break 2)continue 3)pass
1)break: if given condition is satisfied then control goes
outside the loop.
for a in range(1,6):
if a==4:
break
print(a)
op:
1
2
3
2.continue: if control reaches continue it will skip the
current iteration and control goes next iteration.
for a in range(1,6):
if a==4:
continue
print(a)
op:
1
2
3
5
n=5 n=5
st=1 st=5
for a in range(n): for a in range(n):
num=st
num=st for b in range(st):
for b in range(st): print(num,end=' ')
print(num,end=' ') num+=1
num=num+1 print()
print() st-=1
56789
st=st+1 4567
345
1 23
23 1
345 n=5
num=1
4567 for a in range(n):
56789 for b in range(n):
n=4 print(num,end=' ')
st=1 print()
sp=n-1 num+=1
11111
for a in range(n): 22222
num=st 33333
for b in range(sp): 44444
print(' ',end=' ') 55555
for c in range(st):
print(num,end=' ')
num=num-1
print()
num+=1
st=st+2
sp=sp-1
1
321
54321
7654321
r=5
sp=r//2
st=1
for a in range(r):
for b in range(sp):
print(' ',end=' ')
for c in range(st):
print('*',end=' ')
print()
if a<r//2:
st+=2
sp-=1
else:
st-=2
sp+=1
*
***
*****
***
*
r=5
st=1
sp=n//2
for a in range(r):
num=st
for b in range(sp):
print(' ',end=' ')
for c in range(st):
print(num,end=' ')
print()
if a<r//2:
st+=2
sp-=1
else:
st-=2
sp+=1
1
333
55555
333
1
Number programs:
## write a program to check given ## write a program to find sum of digits ## write a program to find
number is prime number or not. in a given number. product of digits in given a
number.
n=int(input(‘enter n value’:) n=55677
a=2345
if n>1: num=n
num=a
for a in range(2,n//2+1): res=0
res=1
if n%a==0: while n!=0:
while a!=0:
print("is not prime") rem=n%10
rem=a%10
break res=res+rem
res=res*rem
else: n=n//10
a=a//10
print('is prime') print(f"{num} value is sum of {res}")
print(f"{num} value product is
else:
{res}")
print('is not prime') ## write a program to check given
number is niven number or not.
## write a program to print
write a program to check given n=8447 prime digits in a given
number is composit number or not. number.
num=n
n=int(input('enter the value:')) n=1245746
res=0
for x in range(2,n//2+1): while n!=0:
while n!=0:
if n%x==0: rem=n%10
rem=n%10
print(f"{n} is composite") n=n//10
res=res+rem
break if rem>1:
n=n//10
else: for x in
if n%res==0:
range(2,rem//2+1):
print(f"{n} is not composit") print(f"{num} is niven")
if rem%x==0:
else:
break
write a program to print factors of a print(f"{num} is not niven")
given number. else:
for x in range(1,n+1):
if n%x==0:
print(x)
## write a program to print ## wap to print factorial of a given
## wap to check given number is
number
prime numbers from 20,30. disarum number or not.
n=5
for a in range(20,31): n=135
fact=1
if a>1: p=len(str(n))
for a in range(1,n+1):
for v in range(2,a//2+1): num=n
fact=fact*a
if a%v==0: res=0
print(fact)
while n!=0:
break
## wap to check given number is
rem=n%10
else: special number or not.
res=res+rem**p
print(a) n=145
p=p-1
## write a program to check num=n
given number is armstrong n=n//10
res=0
number or not. if num==res:
while n!=0:
n= 371 print("disarum number")
rem=n%10
p=len(str(n)) else:
n=n//10
res=0 print("is not dissrum num")
fact=1
num=n ## wap a program to riverse the given
for a in range(1,rem+1):
number.
while n!=0: fact=fact*a
n=123
rem=n%10 res=res+fact
num=n
res=res+rem**p if num==res:
res=0
n=n//10 print("is a special number")
while n!=0:
if res==num: else:
rem=n%10
print("is armstrong num") print("is not special number")
res=res*10+rem
else: ## wap to check given number is
n=n//10
polyprime number or not.
print("is not arm strong num") print(f" revers of{num} is {res}")
n=151
## write a program to odd even ## wap to check given number is
num=n
digits and substract odd digits in palindrome number or not.
a given number res=0
n=121
n=2358746 while n!=0:
num=n
num=n rem=n%10
res=0
res=res*10+rem
res=0 while n!=0:
n=n//10
while n!=0: rem=n%10
if num==res:
rem=n%10 res=res*10+rem
if num>1:
n=n//10 n=n//10
for a in range(2,num//2+1):
if rem%2==0: if num==res:
if num%a==0:
print("is polindrom number")
res=res+rem
print("is not poly prime")
else:
else:
break
print("is not polindrom number")
res=res-rem
else:
print(res) print("is poly prime")
## wap to print all 3 digit disrum ## wap to check given number is
numbers. ## wap to replace value
emirp or not.
for a in range(100,1000): n=23537
n=13
num=a res=0
num=n
res=0 p=1
res=0
p=len(str(a)) while n!=0:
while n!=0:
while a!=0: rem=n%10
rem=n%10
rem=a%10 n=n//10
res=res*10+rem
a=a//10 if rem==3:
n=n//10
res=res+rem**p res=res+6*p
if num!=res:
p=p-1 else:
if num>1:
if num==res: res=res+rem*p
for a in range(2,num//2+1):
print(res) p=p*10
if num%a==0:
print(res)
print("not emirp")
## wap to check given number is # WAP TO CHECK GIVEN NUMBER IS
break AUTOMORPHIC NUMBER OR NOT
strong number or not.
else: a=5
n=6
for b in range(2,num//2+1): s=a*a
num=n
if num%b==0: l=len(str(s))
res=0
print('not emirp') res=s%10**1
for a in range(1,n):
break if res==a:
if n%a==0:
res=res+a print('automorphic')
else: else:
if num==res:
print("is emirp") print('not automorphic')
print("strong")
else: n=192
else:
print("is not emirp") s=str(n*1)+str(n*2)+str(n*3)
print("not strong")
check='123456789'
## wap to convert binary to decimal for a in s:
wap to convert decimal to binary.
n=1110 if str(a) not in check:
n=14
res=0 print('it is not fascinating number')
res=0
p=0 break
x=1
while n!=0: else:
while n!=0:
rem=n%10 print('it is fascinating number')
rem=n%2
n=n//10
n=n//2
res=res+rem*2**p
res=res+rem*x
p=p+1
x=x*10
print(res)
print(res)
# wap to check given number is spy def fib(n): l=[4,2,6,3]
number or not fib=[0,1] for x in range(max(l)):
n=6 for a in range(2,n): for y in range(len(l)):
fib.append(fib[a-2]+fib[a- if l[y]>x:
res1=0 1]) print('*',end=' ')
return fib else:
res2=1
a=fib(7) print(' ',end=' ')
while n!=0: f=a[::2] print()
s=a[1::2] ****
rem=n%10 t=s[::-1] ****
res1+=rem z=f+t * **
n=7 * *
res2*=rem space=0 *
for a in range(n): *
n=n//10
print(' '*space,end='')
if res1==res2: print(z[a]) s=[{'service':'aws'},{'service':'
space=space+1 if a<n//2 azure'},{'os':'windows'},{'os':'l
print('it is spy number') else space-1
inux'}]
0
else:
1 d={}
print('it is not spy number') 3 for a in s:
8 for k,v in a.items():
5 if k not in d:
x=5 2 d[k]=[v]
st=1 1
else:
for a in range(x):
d[k]+=[v]
for b in range(st):
if b==0 or a==x-1 or print(d)
a==b: {'service': ['aws', 'azure'], 'os':
print('*',end=' ') ['windows', 'linux']}
else:
print(' ',end=' ')
print()
st+=1
*
**
* *
* *
****
n=5
for a in range(n):
for b in range(n):
if a==0 or a==n-1 or
b==n-1 or a==n//2:
print('*',end=' ')
print()
*****
*
*****
*
*****
# wap to count each charecter in a
list
list programs a=[1,2,3,1,3,4,5,6]
## wap to print even numbers in given ## wap to print heighest vallue l=[]
a list in a list for x in range(0,len(a)):
n=[11,22,14,15,17,18]
n=[9,14,3,6,7] if a[x] not in l:
for a in range(0,len(n)):
h=n[0] l.append(a[x])
if n[a]%2==0:
for a in range(1,len(n)): print(f'{a[x]}={a.count(a[x])}')
print(n[a])
if h<n[a]: # wap to to sort list (selection sort)
## wap to print even index position of
h=n[a] n=[21,12,15,10,19,16]
a list
print(h) for a in range(0,len(n)-1):
s=[11,12,14,15,18,22,19]
## wap to sort values in list m=a
for a in range(0,len(s)):
without using sort method for b in range(a+1,len(n)):
if a%2==0:
print(s[a])
s=[6,4,3,7,2,8,5] if n[m]>n[b]:
print('not palindrome')
## wap to reverse the given string #wap to convert given string into all
without using slicing . lower case charecters to uppercase
and all uppercase to lowercase
s='vinay'
ch="@#$%^&*" l=n.split()
count=0
for a in range(0,len(s)): d={}
res=''
if s[a] in ch: for a in range(0,len(l)):
for a in range(0,len(s)):
count=count+1 if l[a] not in d:
if s[a] not in res:
print(count) d[l[a]]=1
res=res+s[a]
# wap to print most freequently else:
print(f"{s[a]}={s.count(s[a])}") occured charecter in given a stirrng
d[l[a]]+=1
## pinadi idi same idi inko n='engineering'
val=list(d.values())
methods
d={}
h=val[0]
s='engineering'
for a in range(0,len(n)):
for a in range(1,len(val)):
d={} if n[a] not in d:
if h<val[a]:
for a in range(0,len(s)): d[n[a]]=1
h=val[a]
if s[a] not in d: else:
for k,v in d.items():
d[s[a]]=1 d[n[a]]+=1
if h==v:
else: val=list(d.values())
print(k)
d[s[a]]+=1 h=val[0]
# wap to print most freequently
for k,v in d.items(): for a in range(1,len(val)): occured word in a string
if h==v:
print(k)
# wap to replace the charecteer l=[1,2,3,4,5,0,6,10,7,8,9]
# wap to reverse the string without
e=[]
reversing wordds without using replace method
o=[]
s='vinay is good boy' s='abcdabcd' d={}
for a in range(0,len(l)):
l=s.split() res='' if l[a]%2==0:
for a in range(0,len(l)//2): e.append(l[a])
for a in range(0,len(s)):
else:
l[a],l[len(l)-1-a]=l[len(l)-1-a],l[a] if s[a]=='a': o.append(l[a])
n=e+o
res=' '.join(l)
res+='@' l=[]
print(res) for a in n:
else: if a>1:
# wap to reverse each word in a for x in range(2,a//2+1):
string
res=res+s[a]
if a%2==0:
s='vinay is good boy' print(res) break
else:
l=s.split() l.append(a)
# wap to print all index position of d['even']=e
for a in range(0,len(l)):
d['odd']=o
given chareccter in a string
l[a]=l[a][::-1] d['prime']=l
s='abcbasna' print(d)
res=' '.join(l) output:
print(res)
ch='a' {'even': [2, 4, 0, 6, 10, 8], 'odd': [
1, 3, 5, 7, 9], 'prime': [2, 3, 5, 7,
for a in range(0,len(s)):
9]}
s='aaabbccccbaaf' if s[a]==ch:
res='' print(a)
n='vinay'
count=1 t=int(input('enter table name:'))
for a in range(1,11): res=''
for a in range(0,len(s)-1): print(t,'x',a,'=',t*a)
l=[]
if s[a]==s[a+1]: enter table name: 6
6x1=6 for a in range(-1,-(len(n)+1),-1):
count+=1 6 x 2 = 12
6 x 3 = 18 res=res+n[a]
else:
6 x 4 = 24
res+=str(count)+s[a] 6 x 5 = 30 l.append(res)
6 x 6 = 36 print(l)
count=1 6 x 7 = 42
res+=str(count)+s[a+1] 6 x 8 = 48
6 x 9 = 54
print(res) 6 x 10 = 60 matrix
n=3
l=[[1,2,3],[4,5,6],[7,8,9]]
n='a3b5c7' for i in range(n):
res='' for j in range(n):
for a in range(0,len(n),2): print(l[j][n-1-i],end=' ')
print()
res+=n[a]+(chr(ord(n[a])+int(n[a 369
+1]))) 258
print(res) 147
adbgcj
n=3 l=[[1,2,3],[4,5,6],[7,8,9]]
l=[[1,2,3],[4,5,6],[7,8,9]] n=3
for a in range(3): l=[[1,2,3],[4,5,6],[7,8,9]]
for i in range(n):
for j in range(n): print(l[3-a-1][3-a-1]) for i in range(n):
print(l[n-1-j][i],end=' ') 9 for j in range(n):
print() 5 print(l[n-1-j][i],end=' ')
741 1 print()
852
963 741
l=[[1,2,3],[4,5,6],[7,8,9]]
for a in range(3): 852
n=3 print(l[a][1]) 963
l=[[1,2,3],[4,5,6],[7,8,9]] 2
t=0
5 l1=[1,2,3,4,5]
for i in range(n):
8 l2=[1,2,3,4,5]
for j in range(n):
t+=l[j][i] x=[]
print(t)
l=[[1,2,3],[4,5,6],[7,8,9]] for a in range(len(l1)):
for a in range(3): x.append(l1[a]+l2[a])
45 print(x)
print(l[a][2])
3
6 [2, 4, 6, 8, 10]
l=[[1,2,3],[4,5,6],[7,8,9]]
for a in range(3): 9
for b in range(3):
print(l[a][b],end=' ') n=4
print() l=[[1,2,3],[4,5,6],[7,8,9]] st=4
for a in range(3): for a in range(n):
123 print(l[3-1-a][3-1-a]) for b in range(st):
456 9 if a==0 or a==3 or b==0
789 5 or b==3:
1 print('*',end=' ')
l=[[1,2,3],[4,5,6],[7,8,9]] else:
for a in range(3): print(' ',end=' ')
print(l[a][0]) l=[[1,2,3],[4,5,6],[7,8,9]] print()
1 for a in range(3):
4
****
print(l[a][3-1-a]) * *
7
3 * *
l=[[1,2,3],[4,5,6],[7,8,9]] 5 ****
for a in range(3): 7
print(l[2][a])
7 s1=input('enter string1')
8 l=[[1,2,3],[4,5,6],[7,8,9]] s2=input('enter string2')
9 for a in range(3): if sorted(s1)==sorted(s2):
print(l[3-1-a][a]) print(f'{s1} and {s2} are
l=[[1,2,3],[4,5,6],[7,8,9]] 7 anagrams')
for a in range(3): 5 else:
print(l[0][a]) 3 print('not anagrams')
1
2
enter string1 rajuharivinay
3 n=3
enter string2 vinayhariraju
l=[[1,2,3],[4,5,6],[7,8,9]]
l=[[1,2,3],[4,5,6],[7,8,9]] rajuharivinay and vinayharir
for i in range(n):
for a in range(3): aju are anagrams
for j in range(n):
print(l[a][a]) print(l[j][n-1-i],end=' ')
1
print()
5
9
369
258
147
❖ There are 2 types of functions are there.
• Inbuil functions
• User defined functions
Function:
• It is a block of organized and reused code that we
can executed when function is called.
• Function call is given after function declaration.
• Function is declared by using def keyword.
Ex: def sample():
print(‘vinay’)
sample()
op: vinay
return:
• Return is a key word it is used to return the values
to the function call.
• By using return keyword we can return multiple
values to the function call.
• It takes control flow from fuctional space to main
space. def sum(a,b,c):
return a+b+c
Ex: def sample(): x=sum(10,20,30)
print(x)
print(‘vinay’) y=sum(1,2,3)
print(y)
return 100 # or
def sum(a,b,c):
sample() return a+b+c
op: vinay print(sum(10,20,30))
100 print(sum(1,2,3))
60
6
60
6
Types of arguments:
1. Positional arguments.
2. Keyword arguments
3. Default arguments
4. Variable length non keyword arguments
5. Variable length key word arguments
1.Positional arguments.
• In positional arguments we pass values to the functional call
without name.
• While passing values we need to follow the order.
• no.o arguments in function call and function declaration both
has to be same.
Ex:def details(name,age,gender):
print(f'name : {name}')
print(f'age : {age}')
print(f'gender :{gender}')
details('vinay',25,'male')
op:name : vinay
age : 25
gender :male
2.keyword arguments:
• in keyword arguments we pass values to the function call with
specific variable name.
• no.of arguments in function call and function declaration both
has to be same.
Ex: def details(name,age,gender):
print(f'name : {name}')
print(f'age : {age}')
print(f'gender :{gender}')
details(gender='female',name='vinay',age=25)
Op:name : vinay
age : 25
gender :female
3.default arguments:
• it takes default arguments when we are not pass any values to
the function call.
• No.of arguments in functional call and function declaration no
need to be same.
Ex: def sample(a=0,b=0,c=0):
print(f'a : {a}')
print(f'b : {b}')
print(f'c : {c}') a : 10
sample(10,20,30) b:0
sample(10) c:0
a : 10
b : 20
c : 30
4.variable length keyword arguments:
• It allows a function to accept any no.of values to the function
call.
• Variable name is prefixed with single star.
Ex: def sample(*args):
print(f'args : {args}')
sample(10,20,30)
sample()
args : (10, 20, 30)
args : ()
5.variable length keyword arguments.
• It allows a function to accept any no.of key word arguments.
• Keyword arguments are stored in dictionary.
• Variable name is prefixed with double star(**)
Ex: def star(**kwrgs):
print(f'kwargs : {kwrgs}')
star(a=10,b=20,c=30)
star()
kwargs : {'a': 10, 'b': 20, 'c': 30}
kwargs : {}
# WAP TO PRINT GIVEN NUMBER IS # wap to check given number is
# wap to print factorial of given
PRIME OR NOT polyndrome or not by using function
number number
def prime(n): def reverse(n):
def factorial(n):
if n<=1: res=0
fact=1
return False while n!=0:
for a in range(1,n+1):
for a in range(2,n//2+1): rem=n%10
fact=fact*a
if n%a==0: res=res*10+rem
return fact
return False n=n//10
print(factorial(5))
return True return res
# wap to check the given number is
n=17 n=121 emrip number or not
print('not polyprime')
# wap to check given number is # wap to print 10th number fibnoccie
special number or not series
def factorial(n): def fib(n):
fact=1 f,s=0,1
for a in range(1,n+1): if n==1 or n==2:
fact=fact*a return n-1
return fact for a in range(0,n-2):
def special(n): t=f+s
res=0 f=s
while n!=0: s=t
rem=n%10 return t
res=res+factorial(rem) print(fib(5))
n=n//10 # wap to print first 10 fibnoccie
return res numbers
num=s f,s=0,1
sample()
print(f' global space : {z}')
local space : 500
global space : 500
local variables:
• Local variables are declared as local space or
functional space.
• Local variables can be access only local variables.
def sample():
a=100
print(f' local space : {a}')
sample()
print(f' global space : {a}')
• Local variables can be used in global space by
declaring local variables as global by using global
keyword.
• Global declaration has to be done before assigning
the value.
def sample():
global a
a=100
print(f' local space : {a}')
a=200
sample()
print(f' global space : {a}')
n=lambda x,y:x+y
print(n('vinay','vicky'))
vinayvicky
n=lambda x,y:x//y
print(n(10,2))
5
n=lambda x,y:x%y
print(n(10,2))
0
n=lambda x,y:x*y
print(n(10,2))
20
n=lambda x,y:x**y
print(n(2,3))
8
Filter function:
# filter function is used to filter the values based on
user requirement.
# filter function returns always filter object.
# by using filter function we can avoid loops.
# no.of input values and output values are not same.
l=[10,11,12,13,14,15] def prime(n):
n=list(filter(lambda n:n%2==0,l)) if n<=1:
print(n) return False
[10, 12, 14] for a in range(2,n//2+1):
if n%a==0:
return False
def mod(n): return True
return n%2==0 l=[11,12,13,14,15]
l=[10,11,12,13,14,15] x=list(filter(prime,l))
n=list(filter(mod,l)) print(x)
print(n) [11, 13]
[10, 12, 14]
a file
def fact(n):
t=1
if n==0 or n==1:
return 1
return n*fact(n-1)
def fib(n):
if n==1 or n==2:
return n-1
return fib(n-1)+fib(n-2)
def prime(n):
if n<=1:
return False
for a in range(2,n//2+1):
if n%a==0:
return False
return True
if __name__==’__main__’:
print(prime(5))
print(fib(6))
print(prime(3))
b file
import a
x=a.fact(5)
print(x)
n=a.prime(4)
print(n)
Object:
➢ Object is real time entity that has state and behaviour.
➢ State is defined by using variables and behaviour is
defined by using methods.
➢ Object is created by using class name.
➢ We can create any no.of objects by using class name.
class sample():
pass
n=sample()
print(n)
print(type(n))
op:<__main__.sample object at 0x00000274BA187610>
op:<class '__main__.sample'
advantages of oops:
➢ Bottom to approach
➢ Data security(by using encaptulation)
➢ Code reusability(by using inheritance)
➢ Hiding the data(by using abstraction)
Types of variables:
➢ There are two types of variables are there.
1)class variables
2)object variables
1)class variables:
• Class variables are declared inside the class.
• We can access class variables by using class
name as well object name.
• If we modify class variables by using class
name it affect all the objects that belongs to a
class
• If we modify class variables by using object
name that affect only that particular object.
class jspyders(): class jspyders(): class jspyders():
cname='python fullstac dev' cname='python' cname='python'
tname='santhosh'
tname='vinay' tname='santhosh'
ob1=jspyders()
ob1=jspyders() ob1=jspyders()
ob2=jspyders()
ob2=jspyders() ob2=jspyders() ob3=jspyders()
print(ob1.cname,ob1.tname) ob3=jspyders()
print(ob2.cname,ob2.tname) ob1.cname='java'
print(jspyders.cname,jspyders.tname) jspyders.cname='java' ob1.tname='vinay'
ob1.tname='vinay'
python fullstac dev vinay
python fullstac dev vinay print(ob1.cname,ob1.tname)
print(ob1.cname,ob1.tname) print(ob2.cname,ob2.tname)
print(ob2.cname,ob2.tname) print(ob3.cname,ob3.tname)
print(ob3.cname,ob3.tname)
java vinay
python santhosh
java vinay
python santhosh
java santhosh
java santhosh
class pyspiders():
cname='python development'
tname='vinay'
ob1=pyspiders()
ob2=pyspiders()
def details(obj,name,age,gender,mno):
obj.name=name
obj.age=age
obj.gender=gender
obj.mno=mno
details(ob1,'vinay',21,'male',91193783892)
details(ob2,'madhu',22,'male',98798786787)
print(ob1.name,ob1.age,ob1.gender,ob1.mno)
print(ob2.name,ob2.age,ob2.gender,ob2.mno)
vinay 21 male 91193783892
madhu 22 male 98798786787
1)object variables:
• Object variables are declared inside the constructor
• We can access object variables only by using object
name.
Constructor:
• Constructor is a special method that is called at the time
of object creation.
• Constructor is used to initialize the object
varaibles(members or attributes).
• It takes mandatory argument self that holds address of
the object. class a():
c='vinay'
def __init__(self):
print('constructor called')
ob1=a()
ob2=a()
constructor called
constructor called
class pyspiders():
cname='python development'
tname='vinay'
def __init__(self,name,age,gender,mno):
self.name=name
self.age=age
self.gender=gender
self.mno=mno
ob1=pyspiders('vinay',21,'male',91193783892)
ob2=pyspiders('madhu',22,'male',98798786787)
print(ob1.name,ob1.age,ob1.gender,ob1.mno)
print(ob2.name,ob2.age,ob2.gender,ob2.mno)
types of methods:
1. Object method
2. Class method
3. Static method
1)object method:
➢ object method is used to access and modify object
varaibles(members or attributes).
➢ Object method is called(access) by using object
name.
➢ It takes mandatory argument self that holds
adderess of the object.
class bank():
bname='SBI'
ROI=0.07
def __init__(self,name,mob,acno,bal):
self.name=name
self.mob=mob
self.acno=acno
self.bal=bal
def checkbalence(self):
print(f'{self.name}current account balence is {self.bal}')
def deposit(self,amt):
self.bal+=amt
print('amount deposited')
def withdrawl(self,amt):
if self.bal>=amt:
self.bal-=amt
print('amount debit successfullly')
else:
print('insufficient')
ob1=bank('vinay',9133119384,69676479237923779,15000)
ob1.checkbalence()
ob1.deposit(10000)
ob1.withdrawl(2000)
vinaycurrent account balence is 15000
amount deposited
amount debit successfullly
2)class method:
➢ Class method is declared by using @classmethod decarator.
➢ class method is used to access and modify the class
variables.
➢ Class method is called(access) by using class name as well
object name.
➢ It takes mandatory argument cls that holds address of the
class.
class bank():
bname='ANDHARA BANK'
ROI=0.07
def __init__(self,name,mobn,accn,bal):
self.name=name
self.mobn=mobn
self.accn=accn
self.bal=bal
@classmethod
def changeROI(cls,n):
cls.ROI=n
ob1=bank('amar',99434333,34333403430000,50000)
ob2=bank('vinay',88434333,3433340344564,40000)
ob3=bank('hari',77434333,35555403430000,30000)
ob4=bank('shiva',66434333,876633403430000,20000)
print(ob1.ROI,ob2.ROI,ob3.ROI,ob4.ROI)
ob1.changeROI(0.09)
print(ob1.ROI,ob2.ROI,ob3.ROI,ob4.ROI)
0.07 0.07 0.07 0.07
0.09 0.09 0.09 0.09
3.static method:
• Static method is declared by using @staticmethod
decarator.
• In static method we can’t access class attributes or
object attributes.
• It is access by using class name and object name.
• It will not accept any mandatory argument.
class bank:
bname='RBI'
ROI=0.09
def __init__(self,name,mbn,accn,bal,pin):
self.name=name
self.mbn=mbn
self.accn=accn
self.bal=bal
self.pin=pin
@classmethod
def changeROI(cls,n):
cls.ROI=n
def withdraw(self):
if self.pin==self.getpin():
amt=int(input('enter amount:'))
if self.bal>=amt:
self.bal-=amt
print('amount debited sucessfully')
else:
print('insufficient balence')
else:
print('incorrect pin')
def checkbalence(self):
if self.pin==self.getpin():
print(f'{self.name} current balence is {self.bal}')
else:
print('incorrect pin')
@staticmethod
def getpin():
return int(input('get pin:'))
ob1=bank('vinay',9133119385,8946234724779832749,50000,913
3)
ob1.checkbalence()
ob1.withdraw()
get pin: 9133
vinay current balence is 50000
get pin: 9133
enter amount: 50000
amount debited sucessfull
Getter method: this method is used to get the values of private data
members out side the class.
Setter method: this method is used to modify the values of private
data members outside the class
Class a()
def __init__(self):
self. __x=20
def getter(self):
return self. __x
def setter(self,n):
self. __x=n
obj=a()
print(obj.getter()) op:20
obj.setter(50)
print(obj.getter()) op:50
100
class parent1():
def __init__(self):
print('constructor of class parent1')
class parent2():
def __init__(self):
print('constructor of class parent2')
class child(parent1,parent2):
def __init__(self):
parent1.__init__(self)
parent2.__init__(self)
print('constructor child class')
obj=child()
constructor of class parent1
constructor of class parent2
constructor child class
4.hirarichal inheritance: inheriting properties from one
Parent class to more than one child class is called hiraricha
l inheritance.
class a():
x=100
class b(a):
z=100
y=200
class c(a):
pass
obj=c()
print(obj.x)
100
5.hybrid inheritance: combination of more than one type
of inheritance is called hybrid inheritance.
class a():
x=100
class b(a):
z=100
class c(a):
d=100
class d(b,c):
pass
obj=d()
print(obj.x)
100
method resolution order(MRO): the way of resolving metho
ds and attributes is known as method resolution order.
class a():
pass
class b():
pass
class c(b,a):
pass
print(c.mro())
op: [<class '__main__.c'>, <class '__main__.b'>, <class '__main__.a'>, <class 'object'>]
3.polymorphism:
➢ One object behaving many forms is called polymorphism.
➢ By using both overloading and overriding we can achive poly
morphism.
Overloading:
• Overloading is also known as compile time polymorphism.
• Having same method names with different method signatur
es in a same class.
• In python overloading is not possible because it takes latest
defined method.
sample() sample(2,10)
Types of exception:
1. AttributeError
2. ArithamaticError
I. ZeroDivisionError
II. FloatingPointError
III. OverviewError
3.EoFError
4.NameError
5.LookupError
i)IndexError ii)KeyError
6)stopIterationError
7)OSError
i)FileExistsError
ii)PermitionError
8)ValueError
1)AttributeError:it is raised when we try to print the attribute that
doesnot belongs to class or object then we will get attribute Error.
2)ArithamaticError:
i)ZeroDivisionError: it is raised when we perform True division or
FloorDivision or modular division with 0
5)LookUpError:
i)indexError: it is raised when index is not found in the sequence
ii)keyError: it is raised when key is not found in dictionary.
7)OSError:
i)FileExiastsError: it is raised when user try to create the file that is
already created.
ii)PermitionError: it is raised when we try to open the file that is
protected with password.
try:
▪ in this try block we can write the code to test
▪ when error is raises in try block then control goes to
inside except block.
▪ For try block either except block or finally block need to
be declared.
try: try: try:
x=10 num=120 num=120
print('inside block') l=[2,5,6,'a',0] l=[2,5,6,0,'a']
print(x) for i in l: for i in l:
print(num//i) print(num//i)
except:
except ZeroDivisionError: except ZeroDivisionError:
print('inside except block') print('ZeroDivision error occured') print('ZeroDivision error occured')
except IndexError: except IndexError:
inside block print('index error occured') print('index error occured')
10 except: except:
print('unknown error occured') print('unknown error occured')
60
try: 60 24
print('inside try block') 24 20
print(y) 20 ZeroDivision error occured
unknown error occured
except:
print('inside except block')
try:
inside try block try: l=[10,20,30,0,'a']
inside except block l=[10,20,30,0,'a'] x=60
x=60 print(l[100])
for i in range(len(l)): for i in range(len(l)):
try: print(x//l[i]) print(x//l[i])
l=[1,3,4,0,5,7]
for i in l: except ZeroDivisionError as msg: except ZeroDivisionError as msg:
print(msg) print(msg)
print(l[i])
except TypeError as msg: except TypeError as msg:
except: print(msg)
print('inside except block') print(msg)
except: except IndexError:
print('unexcepted error') print('index error occured')
3 index error occured
0 6
5 3
1 2
7 integer division or modulo by zero
inside except block
except:
▪ If any error raises in try block then except
block will be executed.
▪ For one try block we can write multiple except
blocks.
try:
x='vinay'
print(y)
except:
print('inside except block')
inside except block
6
3
2
no errors are there
finally: it is always executed.
try:
ad=0
l=[1,2,3,'a']
for i in l:
ad+=i
except:
print('error occured')
else:
print('no errors are there')
finally:
print(ad)69
error occured
6
raise: raise is a keyword it is used to through an exceptio
n whenever user need of it.
File handling:
▪ file is a collection of data the data the data is like video
file, audio file ,text file etc.
▪ we have two types of files.
1)text file 2)binary file
1)text file: it is used to store charecters.
2)binary file: binary files have byte code it is used to
store audio files,,video files,image fules etc.
File handling: file handling is nothing but opening a file and
doing some operations like write,read,append access modes
and closing a file
Syntax:
Fileobject=open(‘filename.txt’, ‘access mode’)
Write:
• by using write access mode we can write the content in
a file
• the provided file is not there then it will create a new file
with provided file name.
• if the provided file is already exists then old content is
overridden with new content.
• In write access mode file pointer always starts at
beginning.
read:
• By using read accessmode we can read a content in a
file.
• If the provided file is not there then it will through file
not found error.
• If the provided file is already exists then it will print
content in a file
• In read access mode file pointer always starts at
beginning.
append:
• By using append access mode we can add the additional
content to the file.
• If the provided file is not there then it wil create a new
file with provided file name
• If the file is already exists then it will add additional
content to that file
• In append access mode file pointer is always starts at
end position.
1) wap to print how many charecters are found in a file.
fo=open(‘vinay.txt’, ‘r’)
x=fo.read()
print(len(x)
2) wap to print how many words are found in a file
fo=open(‘vinay.txt’, ‘r’)
x=fo,read()
n=x.split()
print(len(n))
3) wap to print how many lines are present in a file.
fo=open(‘hello.txt’, ‘r’)
fo.readlines()
fo.seek()
l=fo.readlines()
print(len(l))
seek(): it is used for taking the cursor to specified index
position.
Tell(): tell method is used for specifying the current
position of the cursor.
4) wap to print all the words which are starting with ‘ha’
fo=open(‘hello.txt’, ‘r’)
x=fo.read()
y=x.split()
for i in y:
if i.startswith(‘ha’):
print(i)
5)wap to print how many words are present in a file with 5
charecters.
fo=open(‘hello.txt’, ‘r’)
x=fo.read()
y=x.split()
c=0
for i in y:
if len(i)==5:
c+=1
print(c)
regular expression
• regular expression is sequence of charecters that form a
search patterns.
• Regular expression can be used to check if a string
contains the specifies search patterns.
• In oreder to achive regular expression we have to import
re module
1)match:
• It returns a match object if there is a match at starting of
the string.
• It returns none if there is no matches are found.
import re
s='vinay vicky'
x=re.match('v',s)
y=re.match('i',s)
z=re.match('\w{4}',s)
print(x) op: <re.Match object; span=(0, 1), match='v'>
print(y) op:None
print(z) op: <re.Match object; span=(0, 4), match='vina'>
2)search:
• it returns a match object if there is a match anywhere in
the string.
• It returns none if no matches are found.
x='vinay is a python developer'
a=re.search('y',x)
print(a)
<re.Match object; span=(4, 5), match='y'>
3)findall:
• it returns a list containing all matches are and returns an
empty list if no matches are found.
x='vinay is a python developer'
b=re.findall('y',x)
print(b)
['y', 'y']
a='vinay'
x=a.startswith('v')
y=a.endswith('x')
print(x)
print(y)
True
False
Split:
• returns a list where the string has been split at each
match
• by specifying the maxsplit we can control splitting of
parent string.
import re
x='hai how are you'
n=re.split('\s',x)
print(n)
['hai', 'how', 'are', 'you']
6.subn:
• by specifying count we can restrict the replacing
character for not
• more than n times even though string is present.
import re
x='hai hello how are'
n=re.subn('\s','#',x)
print(n)
('hai#hello#how#are', 3)
\d: returns a match where the string contains(numbers from 0_9)
\D: returns a match where the string does not contain digits.
\s: returns a match where the string contain a white space character.
\S: returns a match where the string does not contain a white space charact
er.
W\: returns a match where the string contains any word character(charect
ers from a to z,digits from 0-9 and the underscore character.
\w: returns a match where the string does not contain any word charecters
[abc]: tofind any of a or b or c in souce
[a-c]: to find any of a,b,c,in source
[^abc]: to find all charecters except abc
[0-9]: to find non digit character.
comprehensions
• comprehensions are used for creating new sequences from
iterables or another sequences.
• Comprehensions are single line statements.
• Based on expression if we want to define sequences.
• In python there are 3 types of comprehensions are there.
1)List comprehension
2)Set comprehension
3)dictionary comprehension
1)list comprehension:
One value and one for loop:
l=[i for i in range(1,10)]
print(l)
[1, 2, 3, 4, 5, 6, 7, 8, 9]
m=(11,28,34,99,23,67,90,70)
l=[i for i in m if i%2!=0 and i>50]
print(l)
[99, 67]
m=(11,28,34,99,23,67,90,70)
l=[1 if i%2==0 else 0 for i in range(1,11)]
l=[i for i in m if i%2==1] print(l)
print(l) [0, 1, 0, 1, 0, 1, 0, 1, 0, 1]
[11, 99, 23, 67]
2)dictionary comprehension:
n='abcd'
d={i.upper():i.lower()*3 for i in n}
print(d)
{'A': 'aaa', 'B': 'bbb', 'C': 'ccc', 'D': 'ddd'}
n='abcd'
d={i.upper():i.lower()*3 for i in n}
print(d)
{'A': 'aaa', 'B': 'bbb', 'C': 'ccc', 'D': 'ddd'}
s='pqrs'
d={i:s[i] for i in range(len(s))}
print(d)
{0: 'p', 1: 'q', 2: 'r', 3: 's'}
Enumerate function: enumerate function is used for returning e
numerate object which consists of index positions and its respecti
ve values as pairs.
s='pqrs'
list(enumerate(s))
[(0, 'p'), (1, 'q'), (2, 'r'), (3, 's')]
s='pqrs'
d={k:v for k,v in enumerate(s)}
print(d)
{0: 'p', 1: 'q', 2: 'r', 3: 's'}
s='pqrs'
l=[10,20,30,40]
d={s[i]:l[i] for i in range(len(s))}
print(d)
{'p': 10, 'q': 20, 'r': 30, 's': 40}
Zip function:
s='pqrs'
l=[100,200,300,400]
list(zip(s,l))
s='pqrs'
l='abcdefg'
[('p', 100), ('q', 200), ('r', 300), ('s', 400)] list(zip(s,l))