我有一个清单如下
['T46', 'T43', 'R45', 'R44', 'B46', 'B43', 'L45', 'L44', 'C46', 'C45']
我要根据int值分组的位置:
[id][' ',' ',' ',' ',' '] # AREA PATTERN [Top, Right, Bottom, Left, Center]
[46]['1','0','1','0','1'] #Top,Bottom,Center
[45]['0','1','0','1','1'] #Right,Left,Center
[43]['1','0','1','0','0'] #Top,Bottom
[44]['0','1','0','1','0'] #Right,Left
这可能吗?到目前为止我尝试的是:
id_area = []
for a in area:
id = a[1:3]
areas = a[:1]
if any(str(id) in s for s in area):
id_area = #lost
使用
itertools.groupby()
函数:输出:
我想这就是你要找的
我建议创建一个
dict
,然后基于整数值映射这些值从那里,您可以用
areas
创建一个list
,然后在dict
区域模式中重新赋值相关问题 更多 >
编程相关推荐