Tuple value by key

后端 未结 5 1209
滥情空心
滥情空心 2020-12-08 19:21

Is it possible to get Value out of tuple:

TUPLE = (
    (\'P\', \'Shtg1\'),
    (\'R\', u\'Shtg2\'),
    (\'D\', \'Shtg3\'),
)

by calling S

5条回答
  •  一整个雨季
    2020-12-08 20:04

    You want to use a dictionary instead.

    d = { 'P': 'Shtg1', 'R': u'Shtg2', 'D':'Shtg3' }
    

    And then you can access the key like so:

    d['P'] # Gets 'Shtg1'
    

提交回复
热议问题