counting

python histogram one-liner

徘徊边缘 提交于 2019-12-17 10:18:50
问题 There are many ways to write a Python program that computes a histogram. By histogram, I mean a function that counts the occurrence of objects in an iterable and outputs the counts in a dictionary. For example: >>> L = 'abracadabra' >>> histogram(L) {'a': 5, 'b': 2, 'c': 1, 'd': 1, 'r': 2} One way to write this function is: def histogram(L): d = {} for x in L: if x in d: d[x] += 1 else: d[x] = 1 return d Are there more concise ways of writing this function? If we had dictionary comprehensions

Python- find the item with maximum occurrences in a list

淺唱寂寞╮ 提交于 2019-12-17 07:12:33
问题 In Python, I have a list: L = [1, 2, 45, 55, 5, 4, 4, 4, 4, 4, 4, 5456, 56, 6, 7, 67] I want to identify the item that occurred the highest number of times. I am able to solve it but I need the fastest way to do so. I know there is a nice Pythonic answer to this. 回答1: Here is a defaultdict solution that will work with Python versions 2.5 and above: from collections import defaultdict L = [1,2,45,55,5,4,4,4,4,4,4,5456,56,6,7,67] d = defaultdict(int) for i in L: d[i] += 1 result = max(d

Count specific values in multidimensional array

落花浮王杯 提交于 2019-12-17 05:12:38
问题 I'm trying to count the number of times a certain value appears in my multidimensional array based on a condition. Here's an example array; $fruit = array ( "oranges" => array( "name" => "Orange", "color" => "orange", "taste" => "sweet", "healthy" => "yes" ), "apples" => array( "name" => "Apple", "color" => "green", "taste" => "sweet", "healthy" => "yes" ), "bananas" => array( "name" => "Banana", "color" => "yellow", "taste" => "sweet", "healthy" => "yes" ), "grapes" => array( "name" =>

Using masm to displays the letter that counting in an input string

梦想的初衷 提交于 2019-12-14 03:32:54
问题 Using masm(Visual Studio 2010), write a program that inputs an entire line of text, up to 132 characters, into a buffer. Then have my program determine how many times each letter of the alphabet occurs. You are to count all letter a-z, A-Z, and 0-9 only. The screen should be out put a - 4 times, b - 2 times, c- 9 times. 回答1: I made your program with compiler EMU8086 Intel syntax (just copy-paste-run). It's big but fully commented to help you understand, this is what it does: display a message

How do i go about counting how many times a messagebox appears in c#?

三世轮回 提交于 2019-12-14 03:23:56
问题 I am trying to get my program to Count how many times a certain messagebox in my program appears while it is running. I have looked up how to do this and it seems that I will need to use int count but I'm not sure how to code this for Messageboxes as I can only find count code for strings and arrays. 回答1: It is better idea to make some static wrapper class for MessageBox class and count it there in some kind of static variable. 回答2: There are two solutions for this 1- create a class Adapter

How to merge subarrays by a single key value and count the duplicates?

纵然是瞬间 提交于 2019-12-13 09:32:08
问题 I'm new to stackoverflow and I need some help. I'm trying to remove the duplicates from a multi-dimension array in PHP such as: Array ( [0] => Array ( [Plat] => hello [Data] => 01/01/2015 [Term] => PHP [Quan] => 1 ) [1] => Array ( [Plat] => hello [Data] => 01/01/2015 [Term] => PHP [Quan] => 1 ) [2] => Array ( [Plat] => hello [Data] => 03/01/2015 [Term] => PHP [Quan] => 1 ) [3] => Array ( [Plat] => hello [Data] => 03/01/2015 [Term] => PHP [Quan] => 1 ) [4] => Array ( [Plat] => hello [Data] =>

Counting Number of Months between Two Dates in Excel

元气小坏坏 提交于 2019-12-13 08:57:40
问题 So I am attempting to simply count the number of months bewtween an earlier date and today, which will be in the B:B column; once the number of months have been counted, the result is then multiplied by 28, then added back to the original date. Note the requirement: Result >= Today , so basically if the result is less than today it needs to add another 28 days. The current formula I made only works if the dates are in the current year (and I am not 100% sure if this formula works, it appears

Comparison of value items in a dictionary and counting matches

浪子不回头ぞ 提交于 2019-12-13 07:09:35
问题 Im using Python 2.7. Im trying to compare the value items in a dictionary. I have two problems. First is the iteration of values in a dictionary with a length of 1. I always get an error, because python doesn't iterate integer and a single item as value is an integer for python. I have tried to change the item to a string. I have tried to change the whole dictionary to string. In these cases the iteration compares commas and brackets, as well and thats not the purpose. Therefore I duplicated

Using awk, ignore casesensitve pattern when summarize lines based on the same pattern

最后都变了- 提交于 2019-12-13 05:52:20
问题 Using awk, I would like to ignore case sensitve pattern when summarize lines based on the same pattern. I have the following line (big thanks to Andrey (https://stackoverflow.com/users/3476320/andrey) awk '{n=$1;$1="";a[$0]+=n}END{for(i in a){print a[i], i}}' testing.txt The file contents: 1 Used cars 12 Drivers 1 used cars 1 used cars 14 drivers 2 Used Cars the actual output is 2 Used Cars 14 drivers 12 Drivers 2 used cars 1 Used cars What I need to have: 26 drivers/Drivers (doesn't matter)

Comparing and counting values

僤鯓⒐⒋嵵緔 提交于 2019-12-13 04:48:29
问题 I have a table, let's call it my Individuals Table , much like the one below, containing a column of individuals along with their corresponding codes listed in an adjacent cell. Codes for each individual are all listed within the same adjacent cell next to the individual's name, and separated by a carriage return. Example table What I'd like to do is the following: Run through the code cell for each individual For each code in the individual's code cell, check if this code exists in a