2010年12月30日 星期四

[Python] 將List 內的項目轉換型態

>>> a = ['1', '2', '3', '4']
>>> a
['1', '2', '3', '4']

>>> a[:] = [int(x) for x in a]
>>> a
[1, 2, 3, 4]

See Also:
http://stackoverflow.com/questions/4561113/python-list-conversion
Related Posts Plugin for WordPress, Blogger...