将列表项转换为元组

时间:2012-01-16 05:34:33

标签: python list tuples

我有一个这样的清单。

['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 个答案:

答案 0 :(得分:12)

要制作包含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',)]