针对python list类型的数据类型,可以通过list.index(obj)的形式返回 obj对应的index位置。
aList = [123, 'xyz', 'zara', 'abc'];
print "Index for xyz : ", aList.index( 'xyz' ) ;
print "Index for zara : ", aList.index( 'zara' ) ;
>>Index for xyz : 1
>>Index for zara : 2
... prompt'''
针对dictionary 类型的数据,可以通过dictionary.item()取key 和value
#!/usr/bin/python
# coding=utf-8
dict = {'Google': 'www.google.com', 'Runoob': 'www.runoob.com', 'taobao': 'www.taobao.com'}
print "字典值 : %s" % dict.items()
>>[('Google', 'www.google.com'), ('taobao', 'www.taobao.com'), ('Runoob', 'www.runoob.com')]
#查看一下类型
type(dict.items())
#抓换成DataFrame
df_4 = pd.DataFrame(dict.items() ,columns=['Site', 'Url'])
>>List
# 遍历字典列表
for key,values in dict.items():
print key,values
>>Google www.google.com
>>taobao www.taobao.com
>>Runoob www.runoob.com