header = ['chr', 'pos', 'ms01e_PI', 'ms01e_PG_al', 'ms02g_PI', 'ms02g_PG_al', 'ms03g_PI', 'ms03g_PG_al', 'ms04h_PI', 'ms04h_PG_al']
我想把上面的列表元素转换成元组列表。比如:
sample_list = [('ms01e_PI', 'ms01e_PG_al'), ('ms02g_PI', 'ms02g_PG_al'),
'ms03g_PI', 'ms03g_PG_al'), ('ms04h_PI', 'ms04h_PG_al')]
我认为lambda或列表理解可以用一种简短而全面的方式来处理这个问题。你知道吗
sample_list = [lambda (x,y): x = a if '_PI' in a for a in header ..]
或者
[(x, y) if '_PI' and '_PG_al' in a for a in header]
有什么建议吗?你知道吗
这是一种方法:
试试这个:
输出
您可以筛选列表并删除与所需分组模式不匹配的所有元素:
输出:
相关问题 更多 >
编程相关推荐