Common Words [set 集合 ]

xiaoxiao2025-11-16  6

解法:借用 set 进行集合交运算, 先转换为列表, 再换为集合, 进行交, 再换为列表, 排序, 换为字符串.

# Common Words def checkio(first, second): return ','.join(sorted(list(set(first.split(','))&set(second.split(','))))) #These "asserts" using only for self-checking and not necessary for auto-testing if __name__ == '__main__': assert checkio("hello,world", "hello,earth") == "hello", "Hello" assert checkio("one,two,three", "four,five,six") == "", "Too different" assert checkio("one,two,three", "four,five,one,two,six,three") == "one,three,two", "1 2 3"
转载请注明原文地址: https://www.6miu.com/read-5039747.html

最新回复(0)