从Python列表中的项创建新的空列表?

O.r*_*rka -1 python function list

my_list = ['c1','c2','c3']
Run Code Online (Sandbox Code Playgroud)

反正是否有基于列表中的项目创建一定数量的新列表?

结果将是:

c1 = []
c2 = []
c3 = []
Run Code Online (Sandbox Code Playgroud)

Ash*_*ary 5

你可以这样做globals():

>>> my_list = ['c1','c2','c3']
>>> for x in my_list:
...     globals()[x] = []
...     
>>> c1
[]
>>> c2
[]
>>> c3
[]
Run Code Online (Sandbox Code Playgroud)

但最好在这里使用dict:

>>> dic = {item : []  for item in my_list}
>>> dic
{'c2': [], 'c3': [], 'c1': []}
Run Code Online (Sandbox Code Playgroud)