【问题标题】:I have two values in a Tuple like ('Type', 'RES') can i assign like Type=RES and store it in dict?我在像 ('Type', 'RES') 这样的元组中有两个值,我可以像 Type=RES 一样分配并将其存储在 dict 中吗?
【发布时间】:2014-12-25 09:34:58
【问题描述】:
(u'Type', u'RES')
(u'CustomerId', u'1110566212417')

有没有办法分配 Type = Res 并将其存储在集合中

【问题讨论】:

  • 您需要更加小心您的问题。您希望输出是什么样的?

标签: django python-2.7 django-rest-framework


【解决方案1】:

您可以简单地使用dict 构造函数(它需要一个元组列表并创建一个字典):

pairs = [
    (u'Type', u'RES'),
    (u'CustomerId', u'1110566212417')
]
collection = dict(pairs)

In [1]: collection
Out[1]: {u'CustomerId': u'1110566212417', u'Type': u'RES'}

【讨论】:

  • 谢谢,这很有帮助
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-14
  • 2021-01-12
  • 2020-06-07
  • 1970-01-01
相关资源
最近更新 更多