- 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)

26th Apr 2020, 6:06 AM
kartik malviya
kartik malviya - avatar
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 ;)
26th Apr 2020, 6:18 AM
visph
visph - avatar
0
Can you just tell me how to print a duplicate alphabet count
26th Apr 2020, 6:48 AM
kartik malviya
kartik malviya - avatar
0
You've just to code what you would do manually ;)
26th Apr 2020, 6:50 AM
visph
visph - avatar
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.
26th Apr 2020, 9:46 AM
rodwynnejones
rodwynnejones - avatar
0
import re inp = 'ABBBCCAA' print(''.join('(%i,%s)' % (len(s),c) for s, c in re.findall(r'((.)\2*)',inp)))
26th Apr 2020, 9:47 AM
visph
visph - avatar