2

In python I have fetchall data from the database.

SENTENCE = "It is wonderful. I'am happy"
sent= (word_tokenize(SENTENCE))

cursor = conn.cursor()
format_strings = ','.join(['%s'] * len(sent))
cursor.execute("SELECT emotion_type FROM emotion WHERE key_word IN (%s)" % format_strings,tuple(sent))
results = cursor.fetchall()
for i in results:
        z= (i)

The output is

('happy',)
('happy',)

But I want to get this result as

['happy','happy']

If there is any possible way to get output as I want. Please help me !

Shadow
  • 33,525
  • 10
  • 51
  • 64
Chathurika
  • 419
  • 2
  • 6
  • 18

1 Answers1

1

If the results will only be from a single column, then you can always do

results = [res[0] for res in cursor.fetchall()]
shad0w_wa1k3r
  • 12,955
  • 8
  • 67
  • 90