- 3
given space separated list of alphabet you have to print space separated list of how many times each alphabet appears continue
You are given a space separated list of alphabet you have to print space separated list of how many times each alphabet appears continuously Code in python! Input format- ABBBCCAA Output- (1,A)(3,B)(2,C)(2,A)
5 Antworten
+ 2
your sample in/output doesn't fit your requirements description ^^ (no spaces in beetween each char of the input, nor in beetween count of contiguous letters and you doesn't talk about parenthesis and comma separator for count/letter pairs)...
Anyway, your request looks like homework: we will not do it for you, but we could help if you have a specific problem and you provide your code attempt ;)
0
Can you just tell me how to print a duplicate alphabet count
0
You've just to code what you would do manually ;)
0
Here's a start:
import re
mystring = "ABBBCCAA"
for x in re.finditer(r"([A-Z])\1*", mystring):
pass
# ...now...have a go at manuipulating the 'x' to get the desired output.
0
import re
inp = 'ABBBCCAA'
print(''.join('(%i,%s)' % (len(s),c) for s, c in re.findall(r'((.)\2*)',inp)))