counting

counting punctuation in a given text

谁说我不能喝 提交于 2020-01-06 05:48:08
问题 I have a text file with a huge text written in forms of paragraphs. I need to count certain pieces of punctuation: , and ; from that text without using any module, not even regex . In addition, my program also needs to count ' and - , but only under certain circumstances. Specifically, it should count ' marks, but only when they appear as apostrophes surrounded by letters, i.e. indicating a contraction such as "shouldn't" or "won't" . (Apostrophe is being included as an indication of more

Pythonic way to count specific neighbors in a list

喜你入骨 提交于 2020-01-04 05:19:12
问题 I have a list. For example: [0, 0, 1, 0, 0, 1, 0] I'd like to know what is the most effective way to count the 1 -> 0 transitions. In this case for example the answer is 2 (in the 2-3 and in the 5-6 positions) I tried the following: stat=[0, 0, 1, 0, 0, 1, 0] pair1=stat[:-1] pair2=stat[1:] result=len([i for i in zip(pair1, pair2) if i==(1,0)]) I'm wondering if there is a better way 回答1: Here are 3 ways: from itertools import islice import numpy as np lst = [0, 0, 1, 0, 0, 1, 0] res1 = sum(i -

Counting occurrences of integers in an array [duplicate]

给你一囗甜甜゛ 提交于 2020-01-03 08:26:12
问题 This question already has answers here : Java count occurrence of each item in an array (17 answers) Closed 4 years ago . I'm writing a program that counts the occurrences of integers entered into an array, eg if you entered 1 1 1 1 2 1 3 5 2 3, the program would print out the distinct numbers followed by their occurrences, like this: 1 occurs 5 times, 2 occurs 2 times, 3 occurs 2 times, 5 occurs 1 time And it's almost finished, aside from one problem I can't figure out: import java.util

Counting digit occurrences

情到浓时终转凉″ 提交于 2020-01-02 05:46:04
问题 This problem is really confusing me; we're given two integers A , B , we want to count occurrences of digits in the range [A, B] . I though that if we could count the number of digit occurrences in the range [0, A] and [0, B] , then the rest is trivial. So how can I count digit occurrences in a range [0, x] ? This isn't homework, this is actually a problem from SPOJ. The naive approach won't work, as A and B can be as large as 10 ^ 9. Here are some examples: Input: 1 10 Output: 1 2 1 1 1 1 1

using javascript, how can I count a mix of asian characters and english words

五迷三道 提交于 2020-01-02 03:58:06
问题 I need to take a string of mixed Asian characters (for now, assume only Chinese kanji or Japanese kanji/hiragana/katakana) and "Alphanumeric" (i.e., Enlgish, French), and count it in the following way: 1) count each Asian CHARACTER as 1; 2) count each Alphanumeric WORD as 1; a few examples: 株式会社myCompany = 4 chars + 1 word = 5 total 株式会社マイコ = 7 chars my only idea so far is to use: var wordArray=val.split(/\w+/); and then check each element to see if its contents are alphanumeric (so count as

Fastest way to count number of bit transitions in an unsigned int

╄→尐↘猪︶ㄣ 提交于 2020-01-01 03:15:28
问题 I'm looking for the fastest way of counting the number of bit transitions in an unsigned int . If the int contains: 0b00000000000000000000000000001010 The number of transitions are: 4 If the int contains: 0b00000000000000000000000000001001 The number of transitions are: 3 Language is C. 回答1: int numTransitions(int a) { int b = a >> 1; // sign-extending shift properly counts bits at the ends int c = a ^ b; // xor marks bits that are not the same as their neighbors on the left return CountBits

Counting percentage of element occurence from an attribute in a class. Python

浪尽此生 提交于 2019-12-27 02:47:46
问题 I have a class called transaction that have these attributes Transaction([time_stamp, time_of_day, day_of_month ,week_day, duration, amount, trans_type, location]) an example of the data set is as such timestamp time date weekday duration amount trans_type location 1 0:07 3 thu 2 balance driveup 2 0:07 3 thu 6 20 withdrawal campus a 3 0:20 1 tue 2 357 advance driveup 4 0:26 3 thu 2 20 withdrawal campus b 5 0:26 4 fri 2 35 deposit driveup There are different transaction types. define in trans

xsl:number restarts when count element is wrapped xslt 1.0 xsl-fo

落花浮王杯 提交于 2019-12-25 15:17:12
问题 Given: <dmodule> <content> <procedure> <mainProcedure> <proceduralStep> <proceduralStep id="ps-111-222-test"> <title>Air Valve Assemblies</title> <proceduralStep> <title>General</title><proceduralStep><para>Equivalent substitutes can be used for items listed in the Table</para> </proceduralStep></proceduralStep></proceduralStep> <proceduralStep><para>Continue with this</para><para>Hold air valve plate</para></proceduralStep> <proceduralStep><para>Turn the screw....</para><para>Install bushing

Sub-function in grouping function using dplyr

梦想与她 提交于 2019-12-25 08:48:18
问题 I'm using the dpylr package to count missing values for subgroups for each of my variables. I used a mini-function: NAobs <- function(x) length(x[is.na(x)]) ####function to count missing data for variables to count missing values. Because I have quite some variables and I wanted to add a bit more information (sample size per group, and percentage of missing data per group) I wrote the following code, and inserted one variable (task_1) to check it. library(dplyr) group_by(DataRT, class) %>%

Show words from a file with a minimum given number of vowels

亡梦爱人 提交于 2019-12-25 01:34:25
问题 I'm trying to solve a problem and i can't figure out how to do it. The problem says that given an input file which has on the first line a number k and on the next lines some words, K is the minimum number of vowels that a word needs to have to be printed in the console. Example: Input: test.in cars are...great and awesome Output: If k is 2 the result should be: are great awesome And also it should not take into account spaces or other characters like .,!,? and so on. What i have so far: int