Python - Intersectiing strings

前端 未结 6 560
北海茫月
北海茫月 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条回答
  •  星月不相逢
    2021-01-18 08:54

    easiest is to use sets in python

    >>> a='asdfasdfasfd'
    >>> b='qazwsxedc'
    >>> set(a).intersection(b)
    set(['a', 's', 'd'])
    

提交回复
热议问题