You are given an alphanumeric string. Complete the function sortSegments that will segment the string into substrings of consecutive letters or numbers and then sort the substrings. For example, the string "AZQF013452BAB" will result in "AFQZ012345ABB". The input letters will be uppercase and numbers will be between 0 and 9 inclusive.
Anonymous
import re def segment_sort(string): segments = re.split('([0-9]+)', string) # Splitting the String into Segments sorted_segments = [''.join(sorted(segment)) for segment in segments] return ''.join(sorted_segments) def main(): string = "AZQF013452BAB" print(segment_sort(string)) if __name__ == '__main__': main()
Check out your Company Bowl for anonymous work chats.