我已经定义了一个元组:( slot,gameid,bitrate)
并创建了一个名为的列表myListOfTuples
.在此列表中可能是包含相同的元组gameid
.
例如,列表可能如下所示:
[
(1, "Solitaire", 1000 ),
(2, "Diner Dash", 22322 ),
(3, "Solitaire", 0 ),
(4, "Super Mario Kart", 854564 ),
... and so on.
]
Run Code Online (Sandbox Code Playgroud)
从这个名单,我需要创建对的字典- ( ,gameId
),bitrate
其中bitrate
为gameId
的是我碰到了那个特定的第一个gameId
在myListOfTuples
.
例如,从上面的例子中 - 对的字典只包含一对gameId
"Solitaire":("Solitaire", 1000 )
因为1000是找到的第一个比特率.
NB.我可以创建一组独特的游戏:
uniqueGames = set( (e[1] for e in myListOfTuples ) )
Run Code Online (Sandbox Code Playgroud)
Joh*_*ooy 10
对于python2.6
dict(x[1:] for x in reversed(myListOfTuples))
Run Code Online (Sandbox Code Playgroud)
如果你有Python2.7或3.1,你可以使用katrielalex的答案
归档时间: |
|
查看次数: |
4481 次 |
最近记录: |