这个语法在python中是什么意思[(f,s)表示zip中的f,s(first,second)如果不是f==s]呢

2024-09-28 19:01:30 发布

您现在位置:Python中文网/ 问答频道 /正文

first = "Patient has cancer"
second = "bhagwat has cancer"

def _transpositions(first, second):
    d = [(f, s) for f, s in zip(first, second) if not f == s]
    print(d)
_transpositions(first,second)

其输出为:

[('a', 'h'), ('t', 'a'), ('n', 'a'), (' ', 't'), ('h', ' '), ('a', 'n')]

请解释一下。你知道吗


Tags: inforifdefnotzipfirsthas