Python 列表选择性提取:提取特定方向
import math
mation = [ [1, 0, 1],#5 [0, 1, 1],#2 [-1, 0, 1],#4 [0, -1, 1],#7 [1, 1, math.sqrt(2)],#3 [1, -1, math.sqrt(2)],#8 [-1, 1, math.sqrt(2)],#1 [-1, -1, math.sqrt(2)]#6 ]
您可以通过索引来选择性地提取 'mation' 列表中的特定方向。
例如,如果您想提取方向5和方向2,可以使用以下代码:
direction_5 = mation[0] # 提取方向5
direction_2 = mation[1] # 提取方向2
如果您想提取方向1、方向3和方向7,可以使用以下代码:
direction_1 = mation[6] # 提取方向1
direction_3 = mation[4] # 提取方向3
direction_7 = mation[3] # 提取方向7
通过使用方向对应的索引,您可以选择性地提取 'mation' 列表中的特定方向,并将其赋值给相应的变量。根据您的需求,您可以根据具体的索引选择要提取的方向。
原文地址: https://www.cveoy.top/t/topic/bDlg 著作权归作者所有。请勿转载和采集!