counter

How to count the letters in a word? [duplicate]

馋奶兔 提交于 2019-11-28 14:21:47
This question already has an answer here: Letter Count on a string 11 answers I am trying to make a Python script which counts the amount of letters in a randomly chosen word for my Hangman game. I already looked around on the web, but most thing I could find was count specific letters in a word. After more looking around I ended up with this, which does not work for some reason. If someone could point out the errors, that'd be greatly appreciated. wordList = ["Tree", "Fish", "Monkey"] wordChosen = random.choice(wordList) wordCounter = wordChosen.lower().count['a', 'b', 'c', 'd', 'e', 'f', 'g'

Sum of all counts in a collections.Counter

无人久伴 提交于 2019-11-28 13:15:22
What is the best way of establishing the sum of all counts in a collections.Counter object? I've tried: sum(Counter([1,2,3,4,5,1,2,1,6])) but this gives 21 instead of 9 ? The code you have adds up the keys (i.e. the unique values in the list: 1+2+3+4+5+6=21 ). To add up the counts, use: In [4]: sum(Counter([1,2,3,4,5,1,2,1,6]).values()) Out[4]: 9 This idiom is mentioned in the documentation , under "Common patterns". Sum the values: sum(some_counter.values()) Demo: >>> from collections import Counter >>> c = Counter([1,2,3,4,5,1,2,1,6]) >>> sum(c.values()) 9 sum(Counter([1,2,3,4,5,1,2,1,6])

How to Count Repetition of Words in Array List?

☆樱花仙子☆ 提交于 2019-11-28 11:39:04
问题 I've these code for searching occurrence in Array-List but my problem is how I can get result out side of this for loop in integer type cause I need in out side , may be there is another way for finding occurrence with out using for loop can you help me ? thank you... List<String> list = new ArrayList<String>(); list.add("aaa"); list.add("bbb"); list.add("aaa"); Set<String> unique = new HashSet<String>(list); for (String key : unique) { int accurNO = Collections.frequency(list, key); System

Python - Count number of words in a list strings

两盒软妹~` 提交于 2019-11-28 11:35:56
Im trying to find the number of whole words in a list of strings, heres the list mylist = ["Mahon Point retail park", "Finglas","Blackpool Mahon", "mahon point blanchardstown"] expected outcome: 4 1 2 3 There are 4 words in mylist[0], 1 in mylist[1] and so on for x, word in enumerate(mylist): for i, subwords in enumerate(word): print i Totally doesnt work.... What do you guys think? Use str.split : >>> mylist = ["Mahon Point retail park", "Finglas","Blackpool Mahon", "mahon point blanchardstown"] >>> for item in mylist: ... print len(item.split()) ... 4 1 2 3 The simplest way should be num

Best way to count file downloads on a website

淺唱寂寞╮ 提交于 2019-11-28 11:15:48
It's surprising how difficult it is to find a simple, concise answer to this question: I have a file, foo.zip, on my website What can I do to find out how many people have accessed this file? I could use Tomcat calls if necessary Update: If you suggest writing a script, can you point me to a decent one? Or you could parse the log file if you don't need the data in realtime. grep foo.zip /path/to/access.log | grep 200 | wc -l In reply to comment: The log file also contains bytes downloaded, but as someone else pointed out, this may not reflect the correct count if a user cancels the download on

Animate counter when in viewport

筅森魡賤 提交于 2019-11-28 09:06:37
I have a counter which animates to a final number which is defined in the HTML. However I would like this animation to happen once it's in the viewport. I have a fiddle here which shows how scrolling seems to effect the counter number. $(document).ready(function() { $(function($, win) { $.fn.inViewport = function(cb) { return this.each(function(i, el) { function visPx() { var H = $(this).height(), r = el.getBoundingClientRect(), t = r.top, b = r.bottom; return cb.call(el, Math.max(0, t > 0 ? H - t : (b < H ? b : H))); } visPx(); $(win).on("resize scroll", visPx); }); }; }(jQuery, window)); $("

Automatically count the number of instantiated classes in a TMP?

不问归期 提交于 2019-11-28 08:33:33
Given a template metaprogram (TMP), do C++ compilers produce build statistics that count the number of instantiated classes? Or is there any other way to automatically get this number? So for e.g. the obiquitous factorial #include <iostream> template<int N> struct fact { enum { value = N * fact<N-1>::value }; }; template<> struct fact<1> { enum { value = 1 }; }; int main() { const int x = fact<3>::value; std::cout << x << "\n"; return 0; } I would like to get back the number 3 (since fact<3>, fact<2>, and fact<1> are instantiated). This example if of course trivial, but whenever you start

Why is collections.Counter much slower than ''.count?

南楼画角 提交于 2019-11-28 07:53:17
问题 I have a simple task: To count how many times every letter occurs in a string. I've used a Counter() for it, but on one forum I saw information that using dict() / Counter() is much slower than using string.count() for every letter. I thought that it would interate through the string only once, and the string.count() solution would have to iterate through it four times (in this case). Why is Counter() so slow? >>> timeit.timeit('x.count("A");x.count("G");x.count("C");x.count("T")', setup="x=

Apache Cassandra delete from counter

五迷三道 提交于 2019-11-28 07:06:40
问题 I'm developing a little web application for studying Apache Cassandra and Java EE 6. Cassandra version is 1.1.6. Have a problem driving me mad... I created a table with a counter (using cqlsh v. 3.0.0) CREATE TABLE test ( author varchar PRIMARY KEY, tot counter ) and put some values this way: update test set tot = tot +1 where author = 'myAuthor'; the column family is perfectly updated author | tot ----------+----- myAuthor | 1 BUT, if you try to delete this row and then update again (with

How to get Missed call & SMS count

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 06:07:07
I want to get the count of missed calls and unread messages in my application. and I'd like to open the relevant application when user click on the count. Now biggest problem is how to get the count? I searched online but couldn't find any solution. Thanks in advance. http://developer.android.com/reference/android/provider/CallLog.Calls.html Take a look at this CallLog class. All you need is to query the phone for any calls then extract missed one (оr do this when you are querying the phone, in the selection arguments). The same applies for the messages. SMS are stored in the Content provider