Check whether text contains x numbers in a row [closed] - python

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Is there an option to check whether the given text contains x numbers in a row?
Example:
da$ c0220 -> True
dsad458d69 -> False
I think I should use regular expressions but I can't figure out how.

The regex below checks for 10 consecutive numbers
\d{10}
In Python this becomes
if re.search(r"\d{10}", subject):
# Successful match
else:
# Match attempt failed

Related

Split a string into two in solidity [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 months ago.
Improve this question
I have a list of words like below
["HEllO","HI","GREAT"]
and another list of tuples
[("HELLO",123),("HI",2134),("HELLO",65)]
If all the words in first list comes in second list atleast once then I need True as outcome else False.
Python version (based on comments from
Pranav Hosangadi and matszwecja)
a = ["HEllO","HI","GREAT"]
b = [("HELLO",123),("HI",2134),("HELLO",65)]
not (set(a) - set(x[0] for x in b))

Only print the date in a string [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 months ago.
Improve this question
This is my string
word = " Saturday Fortune 08-09-2022 (4872) Draw Numbers "
But I only want to print the date in the string like this
'08-09-2022'
So how can I achieve this?
Should use a regular expression to find that part in the string. Something like:
import re
match = re.search(r'\d{2}-\d{2}-\d{4}', word)
This already seems to be answered as a subproblem in this thread.

how can I solve this in python? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Id codes at a company come in the form x-y-zzzzzz, where x is a digit and y is a letter and zzzzzz represents a string of 6 letters. Write a function which takes in a code as an input (e.g. 3-a-abaabb) and returns the zzzzzz part (e.g. abaabb).
I have no idea how to start and solve this question. any help would be much appreciated. My IDE is pycharm (solving python coding problems) I basically need to create a function which takes the code as an input and will return the last 6 letters
You can use str.spit('-') then search count in code with repeat is equal or not, like below:
def fnd_code(code):
repeat, char, search = code.split('-')
return search.count(char) == int(repeat)
print(fnd_code('3-a-abaabb'))
print(fnd_code('4-a-abaabb'))
Output:
True
False

HOW TO REMOVE DUPLICATES IN A ROW IN PYTHON [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Hi I need to remove the duplicates in python but only when they are in a row. For example:
Input: AAABBCCDDAA
Output:ABCDA
Could you please help me? thnks.
To learn more about text processing in Python3 I recommend training on codingame.com.
def removeDuplicates(inp):
output =""
lastCharacter=""
for character in inp:
output+=character*(character!=lastCharacter)
lastCharacter=character
return output
inpTest ="AAABBCCDDAA"
print(removeDuplicates(inpTest))
ABCDA

Extract Data Enclosed between three asterisks in python [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I want the data enclosed between three asterisks.And the Word should start with description.
For eg:I have data like
description ***tCore-DFON_P.17-18>dPLUC80115_S19P1>>><<<dPDCL80121_S17P1<100G.IPT.NTTA.SEA.ASE+PC1.LUC/PLD-SEA/PLD_100GEL064.263568***;
I want only
tCore-DFON_P.17-18>dPLUC80115_S19P1>>><<<dPDCL80121_S17P1<100G.IPT.NTTA.SEA.ASE+PC1.LUC/PLD-SEA/PLD_100GEL064.263568
You may use re.findall here:
inp = "description ***tCore-DFON_P.17-18>dPLUC80115_S19P1>>><<<dPDCL80121_S17P1<100G.IPT.NTTA.SEA.ASE+PC1.LUC/PLD-SEA/PLD_100GEL064.263568***;"
matches = re.findall(r'\bdescription\s+\*{3}(.*?)\*{3}', inp, flags=re.DOTALL)
print(matches)
This prints:
['tCore-DFON_P.17-18>dPLUC80115_S19P1>>><<<dPDCL80121_S17P1<100G.IPT.NTTA.SEA.ASE+PC1.LUC/PLD-SEA/PLD_100GEL064.263568']
Note that I use dot all mode in the regex, in case your expected matches might span across more than one line.

Categories

Resources