Python - Intersectiing strings

前端 未结 6 555
北海茫月
北海茫月 2021-01-18 08:26

Trying to write a for function that takes two strings and returns the characters that intersect in the order that they appear in the first string.

Here\'s what I tri

6条回答
  •  梦毁少年i
    2021-01-18 08:52

    You can use python sets http://docs.python.org/library/stdtypes.html#set to do this, like so:

    >>> set("asdfasdfasfd") & set("qazwsxedc")
    set(['a', 's', 'd'])
    

提交回复
热议问题