Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- a = "hellllllllllooooooooooooo"
- match = re.search('(.)\1+', a)
- if match:
- print 'found'
- print re.sub('(.)\1+', '\1', a)
- print re.sub('(.)\1+', '\1\1', a)
- else:
- print 'not found'
- helo
- helloo
- def doppelstring(s):
- letter_groups = ((val, list(group)) for val, group in itertools.groupby(s))
- max_vector = ((val, min(len(group), 2)) for val, group in letter_groups)
- vector_components = ([dim * (l + 1) for l in range(maxlen)] for dim, maxlen in max_vector)
- return [''.join(letters) for letters in itertools.product(*vector_components)]
- def doppelstring_(s):
- max_vector = ((val, min(len(list(group)), 2)) for val, group in itertools.groupby(s))
- vector_components = ([dim * (l + 1) for l in range(maxlen)] for dim, maxlen in max_vector)
- return [''.join(letters) for letters in itertools.product(*vector_components)]
- import re
- def permute(seq):
- if len(seq) < 2:
- yield seq
- else:
- for tail in permute(seq[2:]):
- yield seq[:2] + tail
- yield seq[:2] + seq[1:2] + tail
- text = "hellllllllllooooooooooooo"
- seq = re.split('(.)\1+', text)
- for result in permute(seq):
- print ''.join(result)
- def squeeze(str, chars='abcdefghijklmnopqrstuvwxyz', min=1):
- new_str = str
- for c in chars:
- new_str = new_str.replace(c*(1+min),c*min)
- if new_str != str:
- new_str = squeeze(new_str, min=min)
- return new_str
- >>> squeeze('aaaabbbbcccc')
- 'abc'
- >>> squeeze('aaaabbbbcccc', min=2)
- 'aabbcc'
- def squeezutations(str):
- str = squeeze(str, chars=set(str), min=2)
- for j,k in ((j,k) for j in range(2,0,-1) for k in range(1,3)):
- for c in set(str):
- yield squeeze(squeeze(str, chars=c, min=k), chars=set(str)-set(c), min=j )
- >>> set(squeezutations('appppppppple'))
- set(['apple', 'aple'])
Add Comment
Please, Sign In to add comment