fork download
  1. words = input().split('\n')
  2. num, alpha = words.pop(0).split(' ')
  3. alpha_dict = {letter.upper():index for index,letter in enumerate(alpha)}
  4. words.sort(key = lambda word: [alpha_dict[letter.upper()] for letter in word.upper()])
  5. for word in words:
  6. print(word)
Success #stdin #stdout 0.1s 10088KB
stdin
5 ZYXWVuTSRQpONMLkJIHGFEDCBa
go
aLL
ACM
teamS
Go
stdout
Standard output is empty