我正在尝试获取此列的单词:Suzuki musicChinese musicConservatoryBlue grassRock n rollRhythmCompositionContraInstruments 转换成这种格式:"suzuki music", "chinese music", "conservatory music", "blue grass", "rock n roll", "rhythm"...这是我尝试过的:stuff = [ Suzuki music Chinese music Conservatory Blue grass Rock n roll Rhythm Composition Contra Instruments ]for line in stuff: list.append("'" + line + "',")但是我得到这个错误:文件“ / private / var / folders / jv / 9_sy0bn10mbdft1bk9t14qz40000gn / T / Cleanup At Startup / artsplus_format_script-393966065.996.py”,第2行内容= [^ IndentationError:意外的缩进注销
2 回答
Smart猫小萌
TA贡献1911条经验 获得超7个赞
您正在寻找的string.join
功能
对于您的特定示例,代码如下所示:
', '.join(map(lambda x: '"' + x + '"',stuff))
使用该map
功能与lambda函数一起有效地放在引号每个元素在你的stuff
收藏。
添加回答
举报
0/150
提交
取消