【问题标题】:workaround for getting a list to map to a value in python获取列表以映射到python中的值的解决方法
【发布时间】:2021-06-14 05:37:59
【问题描述】:

下面是一些可重现的代码:

dict = {}

car = 'car'

bike = [4,5,6]

想要的结果是得到

{'car':[4,5,6]}

有没有我能做到的事情

【问题讨论】:

标签: python arrays list dictionary


【解决方案1】:

将列表作为值分配给字典。

 d = {}

car = 'car'

bike = [4,5,6]
d[car] = bike
print(d)

【讨论】:

猜你喜欢
  • 2013-07-07
  • 1970-01-01
  • 1970-01-01
  • 2023-03-26
  • 2021-07-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多