Linked Questions

12 votes
3 answers
22k views

I have a list as follows, consisting of only (-1)s and 1s: list1=[-1,-1,1,1,1,-1,1] I'm trying to append the number of consecutive duplicates into a list, e.g.: count_dups=[2,3,1,1] I've tried ...
2 votes
4 answers
11k views

As mentioned, a run is a sequence of consecutive repeated values. Implement a Python function called longest_run that takes a list of numbers and returns the length of the longest run. For example in ...
Cam's user avatar
  • 49
3 votes
4 answers
3k views

I have a list that contains either 1's or 0's; nothing else. I am interested in finding the 1's and, more specifically, where a run of 1's starts and where that run ends (or in the code below, the "...
user_78361084's user avatar
2 votes
4 answers
2k views

I am looking for a function that gets a one dimensional sorted array and returns a two dimensional array with two columns, first column containing non-repeated items and second column containing ...
Cupitor's user avatar
  • 11.8k
3 votes
1 answer
2k views

I was doing a small program that count the number of times that a character appears in a list and I have a question, ¿Is possible to do it by consecutive numbers?. I have this code now: def function(...
Amartin's user avatar
  • 337
-1 votes
1 answer
407 views

I have a list of strings and numbers l = ['a','a',9,7,'b','c','c','c'] And the output wanted is ['a*2',9,7,'b','c*3'] This is what I have but it can only do '*2' and the last element is not affected ...
Thibaultofc's user avatar
0 votes
2 answers
122 views

I have string value as: s = 'asdabbdasfababbabb' I've split the str by using below code, than get result as below : n = 3 split_strings = [s[index : index + n] for index in range(0, len(s), n)] ['...
0 votes
3 answers
74 views

I have a list in a particular format as follows: my_list = ['apple', 'apple', 'boy', 'cat', 'cat', 'apple', 'apple', 'apple', 'boy', 'cat', 'cat', 'dog', 'dog']. And my expected output ...
BiSu's user avatar
  • 3
183 votes
9 answers
247k views

Assume that I have a set of data pair where index 0 is the value and index 1 is the type: input = [ ('11013331', 'KAT'), ('9085267', 'NOT'), ('5238761', 'ETH'), ...
Hellnar's user avatar
  • 65.4k
94 votes
10 answers
78k views

For example, files, in Python, are iterable - they iterate over the lines in the file. I want to count the number of lines. One quick way is to do this: lines = len(list(open(fname))) However, this ...
Claudiu's user avatar
  • 231k
2 votes
8 answers
15k views

I have some credit card numbers with me and want to validate them over the below rules. ► It must only consist of digits (0-9) ► It may have digits in groups of 4, separated by one hyphen "-" ► It ...
user7422128's user avatar
7 votes
4 answers
5k views

Here's the story I have two lists: list_one=[1,2,9,9,9,3,4,9,9,9,9,2] list_two=["A","B","C","D","A","E","F","G","H","Word1","Word2"] I want to find the indicies of consecutive 9's in list_one so that ...
7 votes
1 answer
814 views

Is there a good way to find stretches of Trues in a numpy boolean array? If I have an array like: x = numpy.array([True,True,False,True,True,False,False]) Can I get an array of indices like: starts =...
-2 votes
6 answers
4k views

I found this practice today: Detect whether a check number is valid or not. The check number must have 10 digits, can not have 2 or more zeros followed, nor three or more digits other than zero ...
Isaac Rivera's user avatar
5 votes
6 answers
140 views

I know there are many other similar questions posted, but there is a difference in mine that makes it unsolvable with their answers. I have several lists of characters that may have multiple ...
TheSprinter's user avatar

15 30 50 per page
1
2