Python列表|如何删除列表中的括号,引号和逗号? [英] Python list | How to remove parenthesis,quotes and commas in my list?

查看:152
本文介绍了Python列表|如何删除列表中的括号,引号和逗号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从数据库中,我返回一个要显示在HTML页面中的列表,但是列表中有不需要的符号.我尝试使用 split()函数,但无法正常工作.如何删除那些括号,逗号和引号.谢谢您的帮助

From my database, I'm returning a list to be displayed into my HTML page but my list has this unwanted symbols. I tried using split() function but it wont work. How can I remove those parenthesis,commas and quotes. Thanks for you help

输出为:

[('cenomar',), ('cedula',), ('Birth Certificate',), ('Clearance',)]

我要

 [cenomar, cedula, Birth Certificate, Clearance]

这是我的python函数:

 @app.route('/')
    def search():
        conn=psycopg2.connect("dbname='forms' user='postgres' password='everboy' 
       host='localhost' port='5432'")
       cur=conn.cursor()
       cur.execute("SELECT name from form")
       rows=cur.fetchall()
       print(rows)
       return render_template("form.html",rows=rows)

推荐答案

在此行之后: rows = cur.fetchall()添加此行

rows=[i[0] for i in rows]

这篇关于Python列表|如何删除列表中的括号,引号和逗号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆