gpt4 book ai didi

python - 连接字符串 : "Multiplication" of two list of strings

转载 作者:行者123 更新时间:2023-11-28 21:36:39 25 4
gpt4 key购买 nike

<分区>

对于字符串列表,在此处将乘法运算定义为连接:

l1 = ['aa', 'bb', 'cc']
l2 = ['11', '22']
l3 = l1 op l2

预期输出:

l3 = ['aa11', 'aa22', 'bb11', 'bb22', 'cc11', 'cc22']

我们可以简单地使用

for l in l1:
for ll in l2:
l3.append(l+ll)

但我很高兴听到 pythonic 解决方案。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com