Skip to content

How to substitute only second occurrence of re.search() group

I need to replace part of the string value with extra zeroes if it needs. T-46-5-В,Г,6-В,Г —> T-46-005-В,Г,006-В,Г or T-46-55-В,Г,56-В,Г —> T-46-055-В,Г,066-В,Г, for example. I have Regex pattern ^D-d{1,2}-([d,]+)-[а-яА-я,]+,([d,]+)-[а-яА-я,]+$ that retrieves 2 separate groups of the string,…

How to merge rows in a Dataframe based on a previous row?

I have a sequentially ordered dataframe that represent two events measured over time – the measurements are the start and end times of the event. They should be ordered in an ABABAB sequence, but in some cases I may have consecutive events of the same type (i.e. ABABAABABB). I am looking for a way to ch…

Collatz’s hypothesis testing in Python

I am trying to build a small program to test the collatz’s hypothesis. So far, I have the following: But when I run it, it’s going into an endless loop of 0.0s. Not really getting where the problem is. Answer As Nearoo mentioned, c0 % 2 is the same as c0 % 2 != 0 because 1 (when c0 is

How can I fix function object is not iterable?

After calling both functions I’m getting ‘function object is not itrable’ as an error. I’m thinking the error appears somewhere in the for loop, I just can’t figure out why if I’m iterating through a list. The purpose of the program is to output the range of numbers between…

Trying to convert input to list

I’m trying to take input from user for 2 points and output the distance. I’m getting stuck on converting the input to a list for the output. I might be thinking about it the wrong way, any help to get me in the right direction is appreciated. Answer You can use a list comprehension to translate th…