String Intersection

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kenninho119
    New Member
    • Mar 2008
    • 1

    String Intersection

    Implement a function strIntersection (str1, str2) that takes two strings as input, and returns the intersection of the two, with each letter represented at most once. The letters should be in the order they appear in the first string.

    eg. strIntersection ("On hot sunny days", "There is much rain") => "n hsua"
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Originally posted by kenninho119
    Implement a function strIntersection (str1, str2) that takes two strings as input, and returns the intersection of the two, with each letter represented at most once. The letters should be in the order they appear in the first string.

    eg. strIntersection ("On hot sunny days", "There is much rain") => "n hsua"
    Create an empty list. Let's call it intlist. Iterate on the first string. If the letter is in the second string but not in intlist, append it to intlist. Return a string with intlist as the argument to ''.join().

    Comment

    Working...