Questions tagged [counter]

A Counter is a container(/bag/multiset/etc.) that keeps track of how many times equivalent values are added.

In Python:

A Counter is a dict subclass for counting hashable objects. It is an unordered collection where elements are stored as dictionary keys and their counts are stored as dictionary values. Counts are allowed to be any integer value including zero or negative counts. The Counter class is similar to bags or multisets in other languages.

http://docs.python.org/library/collections.html#collections.Counter


5262 questions
1
vote
3 answers

Python - Formatting output of most_common

classement=Counter(results) liste = classement.most_common() print(liste) Now what I have with the above print is [(u'a', 5), (u'b', 3), (u'c', 2), (u'd', 2), (u'e', 2), (u'f', 2), (u'g', 2), (u'h', 1), (u'i', 1)] But I would like something like…
Diamonds
  • 117
  • 1
  • 9
1
vote
1 answer

Page Hit Counter - Working but want to limit it to per IP Address

I currently have a working script that counts the number of views and stores them in a .txt file. It's working fine but how do I make it so that it limits to your IP Address? I tried this but it's not counting. // Get filename of Page $pageName =…
Matt
  • 15
  • 4
1
vote
3 answers

tcl add counter to identical list values

I have a list with values: set unnumbered [list 101 101 101 102 102 103 104 105 105 105 106] I want to add a counter to subsequent identical values like this: numbered [ 101.1 101.2 101.3 102.1 102.2 103 104 105.1 105.2 105.3 106] So far I have…
Lumpi
  • 2,697
  • 5
  • 38
  • 47
1
vote
2 answers

How can I apply a Counter to multiple class instances called in a loop?

I am writing a code to serve as a gradebook for a class I teach. While I have a working code without classes, I am learning and trying to incorporate classes into my code. I have a class StudentSpecs. There are a lot of things defined in the class…
user7345804
1
vote
2 answers

Turning column values into Integer columns - Pandas

Given a series of unknown size inner list: import pandas as pd sr = pd.Series([['a', 'b', 'c', 'b'], ['a', 'a', 'd'], ['b']]) [out]: 0 [a, b, c, b] 1 [a, a, d] 2 [b] The goal is to use values in the inner list to create the…
alvas
  • 115,346
  • 109
  • 446
  • 738
1
vote
2 answers

Pythonic way to default loop counters

I sometimes use generators to filter for certain values in programs and want to log the filtered items. Let's assume: def filter_items(items): for item in items: if item.is_wanted(): yield item def process_items(items): …
Richard Neumann
  • 2,986
  • 2
  • 25
  • 50
1
vote
1 answer

JAVA : How to see the difference in output between a synchronized and normal thread counter?

I am trying to understand thread synchronization. I have implemented a counter whose initial value is 0. 10 threads each increment the counter 10 times. I guess the output of the following code must be something that is not 100, since I have not…
1
vote
2 answers

Count occurrences of an element in list

I know that there are already a lot of questions about this specific topic, but I can't find a proper solution for my problem. I have the input: 2, 20, 15, 16, 17, 3, 8, 10, 7 I want to see if there are 'double' numbers in my code. I have tried…
itseva
  • 583
  • 1
  • 4
  • 13
1
vote
1 answer

Textarea counter and limiter in php using javascript

I would like to create textarea character counter and limiter. I have the following codes but for some reason it doesn't work. field($model, 'example', ['template' => '{label}{input}{error}', 'labelOptions' => $class_label]) …
1
vote
2 answers

How to sort word frequency in a list (but not all of them printed) in Python

I have to count the word frequency in a list using python, but what I want is I want to count the words according to its occurance, but I dont't want to print it all For the example, i have this list lists =…
1
vote
4 answers

Python get count of words in a file

I am trying to read the words in a File looks its not working as expected. Can you please let me know if I am missing anything. from collections import Counter wordcount=Counter(f1.read()) for k,v in wordcount.items(): print (k ,v) File…
user826407
  • 159
  • 1
  • 8
1
vote
1 answer

How to do counter with smarty?

I want to do one counter with Smarty. In php I do $i++ to create a counter and after I use if() with if($i%3 == 0). How could I do the same but with Smarty?
oiram16
  • 95
  • 1
  • 9
1
vote
4 answers

Is there a better way to check string for any numbers in it?

basically, Ive been asked to write a program that checks how many times a number is apparent in a string and print it out. This is what i have BufferedReader input = new BufferedReader (new InputStreamReader (System.in)); …
james
  • 55
  • 3
1
vote
3 answers

Finding how many elements from a list you need to reach a certain percentage coverage

I have a long list x = [4,6,7,8,8,8,9,0,9,1,7,7] I know I can use counter to see how many times an item appears. x = [4,6,7,8,8,8,9,0,9,1,7,7] from collections import Counter Counter(x) >>Counter({0: 1, 1: 1, 4: 1, 6: 1, 7: 3, 8: 3, 9: 2}) I can…
user
  • 2,015
  • 6
  • 22
  • 39
1
vote
5 answers

count_word function returns 0 in C

This is my first post on stack overflow :) I didn't find relevant post to my issue despite numerous posts on "counting words". I started C 2 weeks ago. I have to return the number of words in a string, this is part of a larger exercise I m working…
Charles Julien
  • 365
  • 3
  • 16