考虑一下下面的字典:
dict = {'a':2, 'b':3, 'c':1} 我该如何使用键和int值来创建一个像bellow这样的列表呢?
aList = ['a', 'a', 'b', 'b', 'b', 'c']发布于 2021-08-11 12:16:07
LGrementieri答案的一个变体是
[item for key, val in dict.items() for item in [key]*val]https://stackoverflow.com/questions/68311543
复制相似问题