Velocity - Python Coding Questions
Velocity - Python Coding Questions
a = ‘5’
print(int(a))
print(listToStr)
2
Python Question – Velocity Bigdata Batch
8) while i<len(l):
10) l1.append(l[i])
3
Python Question – Velocity Bigdata Batch
12) l1.append(l[i][::-1])
13)i=i+1
14) output=' '.join(l1)
15) print(output)
Python Question – Velocity Bigdata Batch
Output: RTAEVJIA
1) s1='RAVI'
2) s2='TEJA'
3) output=''
4) i,j=0,0
5) while i<len(s1) or j<len(s2):
6) output=output+s1[i]+s2[j]
7) i=i+1
8) j=j+1
9) print(output)
Output: RTAEVJIA
1) s1='RAVI'
2) s2='TEJA'
3) l=list(map(lambda x,y:x+y,s1,s2))
4) print(''.join(l))
Note: The above program can work if the lengths of 2 strings are same.
5
Python Question – Velocity Bigdata Batch
Output:
py test.py Enter First
String:RAVIKIRAN Enter
Second String:TEJA
RTAEVJIAKIRAN
Q9) Assume input string contains only alphabet symbols and digits.
Write a program to sort characters of the string, first alphabet
symbols followed by digits?
1) input: B4A1D3
2) output: ABD134
3)
4) s='B4A1D3'
5) alphabets=[]
6) digits=[]
7) for ch in s:
8) if ch.isalpha():
9) alphabets.append(ch)
10) else:
6
11) digits.append(ch)
12) output=''.join(sorted(alphabets)+sorted(digits))
13) print(output)
7
Python Question – Velocity Bigdata Batch
1) input: a3z2b4
2) output: aaabbbbzz (sorted String)
3)
4) s=input('Enter Some String where alphabet symbol should be followed by digit:')
5) target=''
6) for ch in s:
7)if ch.isalpha():
8) x=ch
9)else:
10) d=int(ch)
11) target=target+x*d
12) output = ''.join(sorted(target))
13) print(output)
1) input: aaaabbbccz
2) output: 4a3b2c1z
3)
4) s='aaaabbbccz'
5) output='' 7) c=1
9) while
6) i<len(s):
previous=s[0]
8) i=1
10)if s[i]==previous:
11) c=c+1
12)else:
13) output=output+str(c)+previous
14) previous=s[i]
15) c=1
16)if i ==len(s)-1:
17) output=output+str(c)+previous
18)i=i+1
19) print(output)
8
Python Question – Velocity Bigdata Batch
1) s='a4k3b2'
2) output=''
3) for ch in s:
4)if ch.isalpha():
5) x=ch
6) output=output+ch
7)else:
8) d=int(ch)
9) newc= chr(ord(x)+d)
10) output=output+newc
11) print(output)
1st way:
1) s='AZZZBCDABBCDABBBBCCCCDDDDEEEEEF'
2) output=''
3) for ch in s:
4) if ch not in output:
5) output=output+ch
6) print(output) # AZBCDEF
9
Python Question – Velocity Bigdata Batch
2nd way:
1) s='AZZZBCDABBCDABBBBCCCCDDDDEEEEEF'
2) l=[]
3) for ch in s:
4) if ch not in l:
5) l.append(ch)
6) output=''.join(l)
7) print(output) # AZBCDEF
1) s='ABCDABXXXBCDABBBBCCCZZZZCDDDDEEEEEF'
2) s1=set(s)
3) output=''.join(s1)
4) print(output) #CAEZBFD
1) s='ABCDABXXXBCDABBBBCCCZZZZCDDDDEEEEEF'
2) l=[]
3) for ch in s:
4) if ch not in l:
5) l.append(ch)
6)
7) for ch in sorted(l):
8) print('{} occurrs {} times'.format(ch,s.count(ch)))
1) s='ABCDABXXXBCDABBBBCCCZZZZCDDDDEEEEEF'
2) d={}
3) for ch in s:
4) d[ch]=d.get(ch,0)+1
5) for k,v in d.items():
6) print('{} occurrs {} times'.format(k,v))
10
Python Question – Velocity Bigdata Batch
1) s='ABAABBCA'
2) output=''
3) d={}
4) for ch in s:
5) d[ch]=d.get(ch,0)+1
6) for k,v in sorted(d.items()):
7) output=output+str(v)+k
8) print(output)
1) s='ABAABBCA'
2) output=''
3) d={}
4) for ch in s:
5) d[ch]=d.get(ch,0)+1
6) for k,v in sorted(d.items()):
7) output=output+k+str(v)
8) print(output)
11
Python Question – Velocity Bigdata Batch
6)d[ch]=d.get(ch,0)+1
Q19) Write a program to check whether the given two strings are
anagrams or not?
Two strings are said to be anagrams iff both are having same content irrespective of
characters position.
12
Python Question – Velocity Bigdata Batch
1) inputs:
2) s1='abcdefg'
3) s2='xyz'
4) s3='12345'
5) output: ax1, by2,cz3,d4,e5,f,g
6)
7) s1='abcdefg' 9) s3='12345'
8)
11)s2='xyz'
while i<len(s1) or j<len(s2) or k<len(s3):
13)ifi=j=k=0
10) i<len(s1):
12)output=''
14) output=output+s1[i]
15) i=i+1
13
Python Question – Velocity Bigdata Batch
16)if j<len(s2):
17) output=output+s2[j]
18) j=j+1
19)if k<len(s3):
20) output=output+s3[k]
21) k=k+1
22)print(output)
Output:
ax1
by2
cz3
d4
e5
f
g
14