Python 数据结构

split(),join()函数

 

List

count(''),index('')

append(''),insert(index,item),extend('')

remove(''),pop(index),pop()

sort()

if item in List:

   print item

 

tuple

count(''),index('')

del tuple

 

Dictionary

Phone = {'alex':'135','ch':'136','wow':'137'}

keys(),values(),items()has_key('')

popitem(),pop('')

Phone['xx'] = '123456789'

for key,value in Phone.items():

  print key,value

 

python 3 Reverse sort

for facetField in DEFAULT_FACET_FIELD:
records=getFacetInfo(facets,facetField)
if(0 < len(records)):
f.write('--'+facetField + '\n')
d_sorted_by_value = OrderedDict(sorted(records.items(), key=lambda x: x[1],reverse=True))
for k,v in d_sorted_by_value.items():
record = k + ',' + str(v) + '\n'

 

HOW TO DEFINE THE VARIABLE TYPEimport types  

if type(bbb) is types.StringType:  

 print "the type of bbb is string" 

if type(aaa) is types.IntType: 

 print "the type of aaa is int"

posted on 2013-09-07 17:19  ukouryou  阅读(151)  评论(0编辑  收藏  举报

导航