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
I want to check if the char in string is English alphabetic or not. I mean, the method is.alpha() will return True if I put Hebrew letter, but I want only English letter.
Check if it is letter and if it is ascii character
def isEnglish(s):
return s.isascii() and s.isalpha()
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 months ago.
Improve this question
How can we reduce a string like haaaaaaapppppyyyyyy to haappyy
Such that repetition is allowed to a maximum of twice in a row for a character in a string?
including any character ( special characters also )
converting --------------------- to --
We can use a regex replacement:
inp = "haaaaaaapppppyyyyyy"
output = re.sub(r'(\w)\1{2,}', r'\1\1', inp)
print(output) # haappyy
The above logic matches any one character which is followed by itself two or more times. It then replaces with just two of the character.
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 8 months ago.
Improve this question
So I want to convert strings to shapes after being given a certain string by the user.
e.g "I love squares" = square shape.
what about just looking for the word to convert to in the string? something like this:
userstring = "I love squares"
if not userstring.find('squares') == -1:
create_square()
if not userstring.find('circle') == -1:
create_circle()
#etc etc
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
str01 = "apple"
In Python, if I am given a specific string, and I want to determine the substring with index 3, how to achieve it?
Depending on what you mean exactly by the substring with index 3:
Substring starting with the character at index 3
>>> str01[3:]
'le'
Substring ending with the character at index 3 (inclusive):
>>> str01[:4]
'appl'
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Is there a function in Python 3 that would allow me to find a substring in any order in a larger string? For example:
ant in Gnat returns True
flat in plat returns False
cooler in polomacear returns True
Here's something I whipped up that will do it. There might be something easier, but it passes tests!
def check(sub, full):
full_list = list(full)
for char in sub:
if char in full_list:
full_list.remove(char)
else:
return False
return True
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 8 years ago.
Improve this question
I took a python course back when i was in high school but now I barely remember anything about it. I'm bored today and though I should try some python exercises.
Example:
string = '3dc8uo8c33a v8c08oizl6ga'
The code needs to remove 3d 8u 8c ... ect
so that the
answer = 'coca cola'
Assuming the rule is "split the string along whitespace, then take every third letter of the words, and add them back together", you can use
>>> string = '3dc8uo8cc33a v8c08oizl6ga'
>>> " ".join("".join(s[2::3]) for s in string.split())
'coca cola'