0
我有一个名为的Python字典top_words。关于打印Python字典的询问
我想打印它的内容,所以我写了这段代码。
for word, count in top_words.items():
print(word, count)
它显示这样的东西。
我怎么能各行之前删除的号码?
top_words字典正在通过此功能生成。
top_word_sequence = 0
top_word_dataset = {}
conn = sqlite3.connect('app.db')
selector = conn.cursor()
query = "SELECT word, count FROM top_words WHERE brand_id = ? ORDER BY count desc LIMIT 10"
selector.execute(query,(brand_id,))
top_words = selector.fetchall()
for single_word in top_words:
top_word_sequence += 1
word = single_word[0]
count = single_word[1]
top_word_dataset[top_word_sequence] = { 'word' : word, \
'count' : count }
return top_word_dataset
您未能显示出什么'top_words'的样子,但我敢打赌,关键是排名,价值是字典中的数据。 –
我的意思是,你不能从印刷输出中弄清楚吗? – n1c9
正如Ignacio所言,“top_words”的外观是什么? – karthikr