Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的代码是:
L=['my', 'my']
我想拆分此列表的项目,以便输出变为:
['my'],['my']
新列表中的每个项目
像这样,使用列表理解:
In [109]: L=['my', 'my'] In [110]: [[x] for x in L] Out[110]: [['my'], ['my']]
或者你可能想要这个:
In [129]: print ",".join(str(x) for x in [[x] for x in L] ) ['my'],['my'] In [130]: print ",".join("[{0}]".format(x) for x in L) [my],[my]