Skip to content

Instantly share code, notes, and snippets.

@akshayapte
Created September 11, 2017 08:39
Show Gist options
  • Save akshayapte/daecb257e4173c4112fb00f2da169d8a to your computer and use it in GitHub Desktop.
Save akshayapte/daecb257e4173c4112fb00f2da169d8a to your computer and use it in GitHub Desktop.
Solution to interview problem
import string
import ast
import sys
rhyme_notes = string.ascii_lowercase+string.ascii_uppercase
vowels = ['a','e','i','o','u','y']
idx = 0
rhyme_dict = {}
ans = ''
ip = raw_input("Enter String Tuple\n")
input_list = ast.literal_eval(ip)
lastspace = False
for elem in input_list:
elem = elem.lower()
if(elem.isspace() or not elem):
if not lastspace:
ans+=' '
lastspace = True
continue
else:
lastspace=False
elem = elem.strip(' ').strip('y').split(' ')[-1]
for index,letter in enumerate(reversed(elem)):
if letter in vowels:
substring = elem[len(elem)-index-1:]
if rhyme_dict.get(substring,None) == None:
ans+=rhyme_notes[idx]
rhyme_dict[substring] = rhyme_notes[idx]
idx += 1
else:
ans+=rhyme_dict[substring]
break
print ans
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment