Skip to content

Instantly share code, notes, and snippets.

@saraswatmks
Created September 1, 2017 12:36
Show Gist options
  • Save saraswatmks/4cd9894149358305555f9af11741fd5f to your computer and use it in GitHub Desktop.
Save saraswatmks/4cd9894149358305555f9af11741fd5f to your computer and use it in GitHub Desktop.
python string
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
@saraswatmks
Copy link
Author

saraswatmks commented Feb 8, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment