修改多级嵌套列表以生成单层列表

2024-05-16 07:49:54 发布

您现在位置:Python中文网/ 问答频道 /正文

如果我有一个由命令dic.keys()形成的列表,如下所示:

[
  "['my', 'modem']", "['technical', 'schematics']", "['still', 'glad']",
  "['spent', 'calling']", "['most', 'feared']", "['the', 'sysop']",
  "['s', 'mystique']", "['had', 'been']", "['of', 'doom']",
  "['i', 'hooked']", "['in', 'california']", "['my', 'ego']",
  "['until', 'my']", "['didn', 't']"
]

键是由str()构成的,所以看起来像list,但它是一个字符串。 我的问题是,你怎么能把每一个项目分开,使它看起来像这样

[ 'my', 'modem', 'techenical', ... ]

Tags: the命令most列表mykeysmodemschematics