在结构化数组中为 header 名称的一部分查找 header 的索引
Finding the index of a header in a structured array for a part of the header name
在我的列表中有
这样的字符串
A_list= ['mass_32_', 'mass_40_', 'mass_28_']
我想从仅包含数字的数组中查找元素的索引。
例如
masses=[32,28]
我想找到与 A_list 中的索引相对应的 mass 中的整数索引。
有什么关于 for/while 循环的建议吗?
试试这个:
[A_list.index('mass_{}_'.format(m)) for m in masses]
在我的列表中有
这样的字符串A_list= ['mass_32_', 'mass_40_', 'mass_28_']
我想从仅包含数字的数组中查找元素的索引。
例如
masses=[32,28]
我想找到与 A_list 中的索引相对应的 mass 中的整数索引。
有什么关于 for/while 循环的建议吗?
试试这个:
[A_list.index('mass_{}_'.format(m)) for m in masses]