0

when i fetch data from a table in SQlite3 it formats each value ('value',) the data in the column: Regi Bob Jeff

how to i remove/ stop the extra round brackets and comma?

c.execute('SELECT Name from information')
data = c.fetchall()
valNameNS = data
valName = str(data)
valNameL = list(valNameNS)
print(valNameL)
[('Regi',), ('Bob',), ('Jeff',)]

Thanks

2
  • I can't even tell what you're asking. Commented Mar 14, 2017 at 19:17
  • how do i remove the round brackets and extra comma Commented Mar 14, 2017 at 19:18

1 Answer 1

2

The items in parenthesis with commas are length-one tuples. Use a list comprehension to extract them.

new_list = [x[0] for x in valNameL]
Sign up to request clarification or add additional context in comments.

1 Comment

Beat me to it. But valNameL is not needed in the first place. You can get rid of those lines (cast to string, using list()) and just use data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.