Last active
August 29, 2015 14:02
-
-
Save avances123/3fb6c343663d59b7f4c4 to your computer and use it in GitHub Desktop.
ejercicios marcos python
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
# http://stackoverflow.com/a/19618657/472866 | |
#import ipdb | |
groups = [] | |
cur_longest = '' | |
prev_char = '' | |
##ipdb.set_trace() | |
for char in s.lower(): | |
if prev_char and char < prev_char: | |
groups.append(cur_longest) | |
cur_longest = char | |
else: | |
cur_longest += char | |
prev_char = char | |
groups.append(cur_longest) | |
if not groups: | |
groups = [s] | |
#print groups | |
print "Longest substring in alphabetical order is: %s" % max(groups, key=len) | |
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
# http://stackoverflow.com/questions/19302525/python-how-to-count-overlapping-occurrences-of-a-substring | |
import re | |
veces = len(re.findall('(?=bob)', s)) | |
print "Number of times bob occurs is: %s" % veces |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment