###実現したいこと
python3.* で以下のような辞書型のデータをpymysqlから全てのデータを引っ張ってきて生成したいです。
lang
1dataset={ 2 'Lisa Rose': { 3 'Lady in the Water': 2.5, 4 'Snakes on a Plane': 3.5, 5 'Just My Luck': 3.0, 6 'Superman Returns': 3.5, 7 'You, Me and Dupree': 2.5, 8 'The Night Listener': 3.0}, 9 10 'Gene Seymour': {'Lady in the Water': 3.0, 11 'Snakes on a Plane': 3.5, 12 'Just My Luck': 1.5, 13 'Superman Returns': 5.0, 14 'The Night Listener': 3.0, 15 'You, Me and Dupree': 3.5}, 16 17 'Michael Phillips': {'Lady in the Water': 2.5, 18 'Snakes on a Plane': 3.0, 19 'Superman Returns': 3.5, 20 'The Night Listener': 4.0}, 21 22 'Claudia Puig': {'Snakes on a Plane': 3.5, 23 'Just My Luck': 3.0, 24 'The Night Listener': 4.5, 25 'Superman Returns': 4.0, 26 'You, Me and Dupree': 2.5} 27}
###質問点
現状、
lang
1 2Array = [] 3with connectionDic.cursor() as cursor: 4 sql = "SELECT * FROM usr " 5 cursor.execute(sql) 6 # Select結果を取り出す 7 results = cursor.fetchall() 8 for r in results: 9 Array = r 10print(Array) 11connection.close() 12
上記のようにすると、
lang
1{'name': 'Lisa Rose', 2 'Lady in the Water': 2.5, 3 'Snakes on a Plane': 3.5, 4 'Just My Luck': 3.0, 5 'Superman Returns': 3.5, 6 'You, Me and Dupree': 2.5, 7 'The Night Listener': 3.0}, 8 9 {'name': 'Gene Seymour', 10 'Snakes on a Plane': 3.5, 11 'Just My Luck': 1.5, 12 'Superman Returns': 5.0, 13 'The Night Listener': 3.0, 14 'You, Me and Dupree': 3.5}, 15 16 {'name': 'Michael Phillips', 17 'Lady in the Water': 2.5, 18 'Snakes on a Plane': 3.0, 19 'Superman Returns': 3.5, 20 'The Night Listener': 4.0}, 21 22 {'name': 'Claudia Puig', 23 'Just My Luck': 3.0, 24 'The Night Listener': 4.5, 25 'Superman Returns': 4.0, 26 'You, Me and Dupree': 2.5}
以上のようになってしまします。この結果から、nameの値を取り出し、子配列
のキーとして与え、さらにそれらをまとめてdatasetのような名前で定義するにはどうしたらよいでしょうか?

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/11/16 08:11