如何遍历列表以创建 n 个连续值的组合并在 Python 中独立使用它们?
How to iterate through a list to create combinations of n successive values and use them independently in Python?
from PIL import Image
imagen_base = Image.open(imagen_base)
a = Image.open(a)
b = Image.open(b)
c = Image.open(c)
d = Image.open(d)
e = Image.open(e)
f = Image.open(f)
lista=[a,b,c,d,e,f]
- 首先,您将有一个基本图像:
image_base = Image.open (image_base)
- 其次,您将有一个图像列表:
a = Image.open(a)
b = Image.open(b)
c = Image.open(c)
d = Image.open(d)
e = Image.open(e)
f = Image.open(f)
list = [a, b, c, d, e, f]
- objective将获得三张新图片;由于模块内的粘贴功能,将 ab、cd 和 ef 组合放在基本图像上方.
如果我没有正确理解你的问题,你只是想找到一种方法来对列表中的 N 个连续项目进行分组?如果是这样,你可以试试:
combined = []
for idx, val in enumerate(_list):
if (_list[idx] == 0) | (idx % 2 == 0):
combined.append((_list[idx], _list[idx + 1]))
哪个 return:
combined = [(a, b), (c, d), (e, f)]
现在,在这个例子中,为了清楚起见,我使用 .append() 方法将它们放回列表中,但您可以将其替换为任务中需要的任何函数。
from PIL import Image
imagen_base = Image.open(imagen_base)
a = Image.open(a)
b = Image.open(b)
c = Image.open(c)
d = Image.open(d)
e = Image.open(e)
f = Image.open(f)
lista=[a,b,c,d,e,f]
- 首先,您将有一个基本图像:
image_base = Image.open (image_base)
- 其次,您将有一个图像列表:
a = Image.open(a)
b = Image.open(b)
c = Image.open(c)
d = Image.open(d)
e = Image.open(e)
f = Image.open(f)
list = [a, b, c, d, e, f]
- objective将获得三张新图片;由于模块内的粘贴功能,将 ab、cd 和 ef 组合放在基本图像上方.
如果我没有正确理解你的问题,你只是想找到一种方法来对列表中的 N 个连续项目进行分组?如果是这样,你可以试试:
combined = []
for idx, val in enumerate(_list):
if (_list[idx] == 0) | (idx % 2 == 0):
combined.append((_list[idx], _list[idx + 1]))
哪个 return:
combined = [(a, b), (c, d), (e, f)]
现在,在这个例子中,为了清楚起见,我使用 .append() 方法将它们放回列表中,但您可以将其替换为任务中需要的任何函数。