python – 将列表项转换为元组

我有这样的清单.

['February 01,2011 - February 28, 2011', 'March 01,2011 - March 31, 2011']

我想把它转换成

[('February 01,2011 - February 28, 2011'), ('March 01,2011 - March 31, 2011')]

有任何想法吗??
请帮忙!!!
提前致谢!!!

解决方法:

要使用1个元素创建元组,请在括号中附加逗号:

>>> my_list = ['February 01,2011 - February 28, 2011', 'March 01,2011 - March 31, 2011']
>>> [(x,) for x in my_list]
[('February 01,2011 - February 28, 2011',), ('March 01,2011 - March 31, 2011',)]
上一篇:python-格式说明符如何通过元组列表时取值


下一篇:c – boost是否提供make_zip_range?