# python遍历列表并在随机点处停止

##### 问题描述投票：0回答：2

``````coordinates = ((20,-125),(50,-115),(80,-95),(100,-75),(120,-50),(130,-20),(125,20),(115,45),(100,75),(75,100),(45,115),(20,120),(-15,120),(-45,115),(-70,100),(-95,70),(-115,50),(-125,20),(-125,-15),(-115,-50),(-100,-75),(-75,-100),(-45,-115),(-10,-125))

for i in coordinates:
pointer.goto(i)

``````
python
##### 2个回答
0

``````import random
coordinates = ((20,-125),(50,-115),(80,-95),(100,-75),(120,-50),(130,-20),(125,20),(115,45),(100,75),(75,100),(45,115),(20,120),(-15,120),(-45,115),(-70,100),(-95,70),(-115,50),(-125,20),(-125,-15),(-115,-50),(-100,-75),(-75,-100),(-45,-115),(-10,-125))

coordinates = [x for x in coordinates]

random.shuffle(coordinates)
for i in coordinates:
## do something
``````

0

``````import random

coordinates = ((20,-125),(50,-115),(80,-95),(100,-75),(120,-50),(130,-20),(125,20),(115,45),(100,75),(75,100),(45,115),(20,120),(-15,120),(-45,115),(-70,100),(-95,70),(-115,50),(-125,20),(-125,-15),(-115,-50),(-100,-75),(-75,-100),(-45,-115),(-10,-125))

stop_point = random.randrange(len(coordinates))

for i in coordinates[:stop_point]:
pointer.goto(i)
``````