Skip to content

Latest commit

 

History

History
46 lines (27 loc) · 699 Bytes

Two_to_One.md

File metadata and controls

46 lines (27 loc) · 699 Bytes

CodeWars Python Solutions


Two to One

Take 2 strings s1 and s2 including only letters from a to z. Return a new sorted string, the longest possible, containing distinct letters,

  • each taken only once - coming from s1 or s2.

Examples

a = "xyaabbbccccdefww"
b = "xxxxyyyyabklmopq"
longest(a, b) -> "abcdefklmopqwxy"

a = "abcdefghijklmnopqrstuvwxyz"
longest(a, a) -> "abcdefghijklmnopqrstuvwxyz"

Given Code

def longest(s1, s2):
    pass

Solution

def longest(s1, s2):
    return "".join(sorted([c for c in set(s1 + s2)]))

See on CodeWars.com