gpt4 book ai didi

bash - linux bash 中 python zip() 函数的等价物是什么?

转载 作者:行者123 更新时间:2023-12-05 09:28:15 25 4
gpt4 key购买 nike

<分区>

我想在 bash 中迭代成对的元素。在 Python 中,这是直截了当的:

x_list = [1, 2, 3, 4]
y_list = ["a", "b", "c", "d"]

for x, y in zip(x_list , y_list):
# here we have access to the values (i.e. the pairs are assigned to variables):
result = do_something(x, y)
print(result)

如何在 bash 中复制这样的行为?我需要将对的值存储到 for 循环内的变量中,以便我可以执行一些操作。它应该是这样的:

for x, y in 1a 2b 3c 4d
do
python script.py --x_value=${x} --y_value=${y}
done

请注意,列表的元素也可以是复杂的东西,例如:x_list = [1e-5, 1e-4, 1e-3]y_list = [10, 20, 30]

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