counting

How to count triplets of i,j,k such that i < j < k

How to count triplets of i,j,k such that i < j < k Question: I want to know an efficient way of calculating the count of triplets i, j, and k such that i < j < k. I’ve tried using the following code: for i in range(n): for j in range(i + 1, n): …

Total answers: 1

How write file length in another file using a loop?

How write file length in another file using a loop? Question: I am attempting to write a file which compares the amounts of permutations available for three numbers. The current script is tmp = open("tmp_out.txt","w+") out = open("output_trip.txt", "w") N = 4 for k in range(2,N+1): count = 1 for j in range(1,k): for i …

Total answers: 1

Count consecutive row values but reset count with every 0 in row

Count consecutive row values but reset count with every 0 in row Question: Within a dataframe, I need to count and sum consecutive row values in column A into a new column, column B. Starting with column A, the script would count the consecutive runs in 1s but when a 0 appears it prints the …

Total answers: 2

Special case of counting empty cells "before" an occupied cell in Pandas

Special case of counting empty cells "before" an occupied cell in Pandas Question: Pandas question here. I have a specific dataset in which we are sampling subjective ratings several times over a second. The information is sorted as below. What I need is a way to "count" the number of blank cells before every "second" …

Total answers: 1

What is the difference between two codes that count words in a text?

What is the difference between two codes that count words in a text? Question: Hello I was trying to count words in a text but there’s a problem. If I write code like def popular_words(text:str, list:list)-> dict: text=text.lower() splited_text=text.split() answer={} for word in list: answer[word]=splited_text.count(word) return answer print(popular_words(”’ When I was One I had just …

Total answers: 1

Fastest way to count frequencies of ordered list entries

Fastest way to count frequencies of ordered list entries Question: I’m counting the occurrences of non-overlapping grouped subsequences of length i in a binary list, so for example if I have a list: [0, 1, 0, 1, 1, 0, 0, 0, 1, 1], I want to count occurrences of [0,0] (one), [0,1] (two), [1,0] (one), …

Total answers: 5

How do I count the last elements in a list after a certain element?

How do I count the last elements in a list after a certain element? Question: I have a python list containing zeros and ones like this: a = [1.0 1.0 0.0 0.0 1.0 0.0 1.0 0.0 0.0] I know how to count the ones and zeros in this, but what I can’t manage to figure …

Total answers: 3

How do I count the letters in Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch?

How do I count the letters in Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch? Question: How do I count the letters in Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch? print(len(‘Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch’)) Says 58 Well if it was that easy I wouldn’t be asking you, now would I?! Wikipedia says (https://en.wikipedia.org/wiki/Llanfairpwllgwyngyll#Placename_and_toponymy) The long form of the name is the longest place name in the United Kingdom and one of …

Total answers: 4