Focus next input once reaching maxlength value

No jQuery used and is a very clean implementation: Reads from the maxlength attribute. Scales to any number of inputs inside of your container. Automatically finds the next input to focus. No jQuery. http://jsfiddle.net/4m5fg/5/ <div class=”container”> a: <input type=”text” maxlength=”5″ /> b: <input type=”text” maxlength=”5″ /> c: <input type=”text” maxlength=”5″ /> </div> .. var container … Read more

Surprising results with Python timeit: Counter() vs defaultdict() vs dict()

Yes, this is expected; the Counter() constructor uses Counter.update() which uses self.get() to load initial values rather than rely on __missing__. Moreover, the defaultdict __missing__ factory is handled entirely in C code, especially when using another type like int() that is itself implemented in C. The Counter source is pure Python and as such the … Read more

Pandas groupby.size vs series.value_counts vs collections.Counter with multiple series

There’s actually a bit of hidden overhead in zip(df.A.values, df.B.values). The key here comes down to numpy arrays being stored in memory in a fundamentally different way than Python objects. A numpy array, such as np.arange(10), is essentially stored as a contiguous block of memory, and not as individual Python objects. Conversely, a Python list, … Read more

Count characters in textarea

What errors are you seeing in the browser? I can understand why your code doesn’t work if what you posted was incomplete, but without knowing that I can’t know for sure. You should probably clear the charNum div, or write something, if they are over the limit. function countChar(val) { var len = val.value.length; if … Read more

How to count the frequency of the elements in an unordered list?

In Python 2.7 (or newer), you can use collections.Counter: import collections a = [1,1,1,1,2,2,2,2,3,3,4,5,5] counter=collections.Counter(a) print(counter) # Counter({1: 4, 2: 4, 3: 2, 5: 2, 4: 1}) print(counter.values()) # [4, 4, 2, 1, 2] print(counter.keys()) # [1, 2, 3, 4, 5] print(counter.most_common(3)) # [(1, 4), (2, 4), (3, 2)] print(dict(counter)) # {1: 4, 2: 4, … Read more