有没有像 list[select_all] in turtle python 这样的东西?

Is there anyway do something like list[select_all] in turtle python?

所以我正在 python 海龟中制作一个游戏,其中有很多克隆。我已将不同的克隆放入不同的列表。

如果 turtle.distance(list[select_all])?

我该如何做

我真的需要你的帮助,因为我不想写一行长达一百个字母的代码。谢谢

如果我没理解错的话,你想要 uber_list 游戏中所有的海龟。我认为您可以将列表推导式与列表列表一起使用:

a = [1,2,3,4,5] #list 1
b = [6,7,8,9,10] #list 2
c = [a,b] # list of lists
d = [element for array in c for element in array] # get every element from every list
print(d)
#Prints [1,2,3,4,5,6,7,8,9,10]

总而言之:创建一个列表列表,然后使用嵌套的 for 循环创建一个列表推导式。希望这对您有所帮助。

如果其他答案是您所需要的,这可能是一种更有效的方法(如果不是请赐教)

a = [1, 2, 3]
b = [4, 5, 6]
c = a + b

充实一个完整的例子,我想我不会使用 any()all() 而是使用 filter() 来找到在指定距离内的实际海龟目标:

from turtle import Screen, Turtle
from random import randint
from itertools import chain

screen = Screen()

prototype = Turtle()
prototype.hideturtle()
prototype.shape('turtle')
prototype.penup()

red = []  # a bunch of randomly placed red turtles
for _ in range(15):
    turtle = prototype.clone()
    turtle.color('red')
    turtle.goto(randint(-200, 200), randint(-200, 200))
    turtle.showturtle()
    red.append(turtle)

green = []  # a bunch of randomly placed green turtles
for _ in range(15):
    turtle = prototype.clone()
    turtle.color('green')
    turtle.goto(randint(-200, 200), randint(-200, 200))
    turtle.showturtle()
    green.append(turtle)

yellow = prototype.clone()  # our target turtle
yellow.color('yellow')
yellow.goto(randint(-200, 200), randint(-200, 200))
yellow.showturtle()

closest = filter(lambda t: yellow.distance(t) < 100, chain(red, green))

for turtle in closest:  # turtles closest to yellow turtle turn blue
    turtle.color('blue')

screen.exitonclick()