我有一个嵌套列表main_category,每个嵌套列表是一个unicode字符串的商业名称。嵌套表的前五行低于:Python列表索引超出范围嵌套列表
[[u'Medical Centers', u'Health and Medical'],
[u'Massage', u'Beauty and Spas'],
[u'Tattoo', u'Beauty and Spas'],
[u'Music & DVDs', u'Books, Mags, Music and Video', u'Shopping'],
[u'Food', u'Coffee & Tea']]
所以我想每个列表的第一个元素,我已经试过列表理解,拉链,但没有任何工程。
new_cate = [d[0] for d in main_category]
lst = zip(*main_category)[0]
但他们都给予我
IndexErrorTraceback (most recent call last)
<ipython-input-49-4a397c8e62fd> in <module>()
----> 1 lst = zip(*main_category)[0]
IndexError: list index out of range
我真的不知道什么是错。那么谁能帮忙?非常感谢!
你能确认你执行的代码? [医学中心],'按摩','纹身','音乐和DVD','食物']和('医疗中心','按摩','纹身','音乐&DVDs','Food') –
您的完整列表包含一个空子列表'[]'在某处。确认。 –
[在python中提取每个子列表的第一项可能的重复](http://stackoverflow.com/questions/25050311/extract-first-item-of-each-sublist-in-python) –