How to make a function return a list of indices of the characters in the second string that appears in the first string?

后端 未结 4 1670
孤街浪徒
孤街浪徒 2021-01-25 08:54
def get_indices_from_the_second_string(string1, string2):
    \'\'\'(str, str) -> list of int
    >>> get_indices_from_the_second_string(\'AGTACACGTTAC\', \'         


        
4条回答
  •  别那么骄傲
    2021-01-25 09:39

    Use the built in function zip, along with another built in enumerate

    acc = []
    for i, (a, b) in enumerate(zip(string1, string2)):
        if a==b:
            acc.append(i)
    return acc
    

提交回复
热议问题