-1
我正在填充表格的元组名单上:如何找到具有特定值的所有元组?
tups = [(1, 2, 4.56), (2, 1, 1.23), (1, 3, 2.776), ...]
,我想执行两个操作。
首先是要找到开始用数字Ñ的所有元组,例如:
def starting_with(n, tups):
'''Find all tuples with tups that are of the form (n, _, _).'''
# ...
而第二个是相反的,找到的Ñ第二值的所有元组:
def middle_with(n, tups):
'''Find all tuples with tups that are of the form (_, n, _).'''
# ...
从某种意义上说,在元组列表上进行模式匹配。我如何在Python中做到这一点?
哦,真不错,谢谢! – sdasdadas
有趣的替代... –
但我认为第一种方法会更快 –