Created
September 1, 2017 12:36
-
-
Save saraswatmks/4cd9894149358305555f9af11741fd5f to your computer and use it in GitHub Desktop.
python string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
strn = 'abcbaabbcc' | |
d = {} | |
k = 2 | |
prev_word = strn[0] | |
c = 1 | |
for s in strn[1:]: | |
if prev_word == s: | |
c+=1 | |
print('this is c = {} in first loop'.format(c)) | |
else: | |
if k == c: | |
d[prev_word] = c | |
print('this is d = {} in first loop'.format(d)) | |
c = 1 | |
prev_word = s | |
print(d) | |
for k, v in sorted(d.items()): | |
print (k) | |
break | |
######################## | |
from collections import Counter | |
string = "abcbaabbccc" | |
counter = Counter(strn) | |
for key, value in sorted(d.items()): | |
if v == k: | |
print k | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is simpler:
for i in stri: d[i] = d.get(i, 0)+1 if d[i] == 2: print(i) print('this is the answer') break