enumerate Counter in python

the facebook hackerCup 2013:

[find the beauty of a string]

the linkage below gives a novel and clear solution using python: 

http://notes.tweakblogs.net/blog/8648/facebook-hacker-cup-2013-qualification-round-problem-analysis.html

enumerate ( sequencestart=0 )

Return an enumerate object. sequence must be a sequence, an iterator, or some other object which supports iteration. The next() method of the iterator returned by enumerate() returns a tuple containing a count (from start which defaults to 0) and the values obtained from iterating over sequence:

>>> seasons = ['Spring', 'Summer', 'Fall', 'Winter']
>>> list(enumerate(seasons))
[(0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter')]
>>> list(enumerate(seasons, start=1))
[(1, 'Spring'), (2, 'Summer'), (3, 'Fall'), (4, 'Winter')]

Another important data structure: collection:
ps: IBM doc provides a series of docs about the collection in Java.
linkage : http://www.ibm.com/developerworks/cn/java/j-5things2.html
We mainly focus on the Counter object: A counter tool is provided to support convenient and rapid tallies
1> Counter is a dict subclass for counting hashable objects.
2> Counter objects support three methods beyond those available for all dictionaries:
    1) elements(): which can rebuild a list ( or iterator) easily.
   2) most_common(n) : Return a list of the n most common elements and their counts from the most common to the least
    3) subtract
3> Counter objects have a dictionary interface except that they return a zero count for missing items instead of raising a KeyError

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值