正如标题所说,我正在尝试在 Python 中动态命名列表。该代码的目的是围绕连续字母创建列表。这是我的代码:
consecutive_duplicates=["a","a","a","a","b","c","c","a","a","d","e","e","e","e","X"]
count=0
name=0
for i in consecutive_duplicates:
if consecutive_duplicates[count]==consecutive_duplicates[count+1] or
consecutive_duplicates[count]==consecutive_duplicates[count-1]:
consecutive_duplicates[name].append(i)
count=count+1
else:
consecutive_duplicates[name+1].append(i)
name=name+1
我不知道如何命名列表。显然,这不起作用。什么会让它发挥作用?
我也无法定义动态列表。我该怎么做?