suz
BAN USERdef find_substrings(words, parts):
sorted_parts = sorted(parts, key=len, reverse=True)
return [return_word_with_bracketed_part(word, parts) for word in words]
def return_word_with_bracketed_part(word, sorted_parts):
for part in sorted_parts:
if part in word:
return word.replace(part, "[{part}]".format(part=part))
return word
def check_order(input, ordering):
chars_in_ordering = set([char for char in ordering])
chars_to_process = iter(ordering)
target_char = chars_to_process.next()
processed = set()
for i in input:
if i == target_char or i not in chars_in_ordering:
pass
elif i in processed:
return False
else:
processed.add(target_char)
target_char = chars_to_process.next()
return True
- suz July 11, 2018