清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #coding=utf-8 print 'I am ' ,__name__ def getClassify(lists): res = {} for item in lists: if isinstance(item,int): res[ 'int' ] = res.get( 'int' , 0 ) + 1 elif isinstance(item,basestring): res[ 'str' ] = int(res.get( 'str' , 0 )) + 1 elif isinstance(item,list): res[ 'list' ] = int(res.get( 'list' , 0 )) + 1 elif isinstance(item,tuple): res[ 'tuple' ] = int(res.get( 'tuple' , 0 )) + 1 elif isinstance(item,dict): res[ 'dict' ] = int(res.get( 'dict' , 0 )) + 1 else : res[ 'others' ] = int(res.get( 'others' , 0 )) + 1 return res def getClassify2(lists): typeflag = type(lists[ 0 ]) rest = {} rest[typeflag] = 1 for each in lists[ 1 :]: if type(each) = = typeflag: rest[typeflag] = rest.get(typeflag, 0 ) + 1 else : typeflag = type(each) rest[typeflag] = rest.get(typeflag, 0 ) + 1 return rest if __name__ = = "__main__" : lists = [ 1 , 2 , '2' , '3' , 'a' ,( 1 , 2 , 3 ),[ 3 , 4 , 5 , 6 ],{ 'spam' : 'ham' }, None ] print getClassify(lists) print getClassify2(lists) |