2024-04-18 05:04:29 发布
网友
通过删除括号中的括号和逗号,尝试将列表1变成下面代码中所示的列表2,以便我可以将字符串用于SQLite select查询:
[('Mark Zuckerberg',), ('Bill Gates',), ('Tim Cook',), ('Wlliam Sidis',), ('Elon Musk',)] ['Mark Zuckerberg', 'Bill Gates', 'Tim Cook', 'William Sidis', 'Elon Musk']
假设你有这样一张单子
animal_raw = [('cat', ), ('dog', ), ('elephant', )]
现在我们将把它转换成你要求的,没有逗号和括号的。在
现在,print(animal)。 现在你应该得到输出
print(animal)
['cat', 'dog', 'elephant']
在获取行并在列表中存储时使用str(row)
list=[('Mark Zuckerberg',), ('Bill Gates',), ('Tim Cook',), ('Wlliam Sidis',), ('Elon Musk',)] listoutput=[i[0] for i in list] print(listoutput)
Check output below
从元组中,我们可以按索引访问元素tuple[index]
tuple[index]
单元素元组python表示为
(element,)
你有元组列表
或短版
b = [i[0] for i in a]
假设你有这样一张单子
现在我们将把它转换成你要求的,没有逗号和括号的。在
^{pr2}$现在,
print(animal)
。 现在你应该得到输出在获取行并在列表中存储时使用str(row)
从元组中,我们可以按索引访问元素
tuple[index]
单元素元组python表示为
你有元组列表
^{pr2}$或短版
相关问题 更多 >
编程相关推荐