How to identify common substrings of two strings in Python? [closed] - python

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 1 year ago.
Improve this question
How can I find common substrings of two strings in order to show changes/edit of a string?
So what I try to do is to compare an old version of a string:
string_old = "My name is pm730! How are you?"
with a new/edited version of the string:
string_new = "My name isn't pm730, it is pm740!"
Deleted substrings are not important. New substrings should be distinguished somehow, so that I could output it like this eventually:
My name isn't pm730 , it is pm740!
This task sounds easy but is more complicated than I thought. So my hope is that there is already an similar implementation available, but unfortunanly I can't find it...

Related

Filtering string column with specific character [closed]

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 1 year ago.
Improve this question
I have a string column like this and want to filter content between "/" character:
A
9/17/001.a.x.y.16.04451
006.b.021017006814
2/17/000.c.m.n.15.00668/008
And the expected output is
A
001.a.x.y.16.04451
006.b.021017006814
000.c.m.n.15.00668
How could i make it done with python/R/Mysql
Thank youuu
In MySQL, you can use regexp_replace():
select t.*,
regexp_replace(a, '^[^/]+/[^/]+/([^/]*)[/|^]', '$1')
from t;
The logic is that you seem to want the third component between slashes if there is one. Otherwise, you seem to want the entire string.
Here is a db<>fiddle.

Regex required for following string [closed]

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 2 years ago.
Improve this question
search?query=EasterGmPromo2020&searchType=mktgattribute&monet=CURATED&fulfillment=all
I have such type of strings. I wanted to get data from ?query=EasterGmPromo2020 only. How to do in regex.
This is a query string. There are many packages out there that parse URLs, no need for regex here.
One way is to use urllib.parse (built into Python 3)
from urllib import parse
params = parse.parse_qs("query=EasterGmPromo2020&searchType=mktgattribute&monet=CURATED&fulfillment=all")
print(params["query"])

How can I write this in one line? [closed]

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 3 years ago.
Improve this question
Hey So I'm working on a problem that asks me to manipulate a dictionary by grabbing all the keys and values and formatting them into a single string for every key/value pair. I have to do this in one line, or so I think, the problem is better explained in the image.
I believe they would like you to write for country, pop in country_pop.items(): on line 7. However, you can do the entire thing in one line as well.
print('\n'.join([f'{key} has {value} people' for key, value in country_pop.items()]))

Python String Expression format [closed]

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 3 years ago.
Improve this question
I am not understanding the meaning of each of the terms in the curly brackets (I was a bit overwhelmed with this source https://docs.python.org/3.4/library/string.html)
def format_money(amount):
return '${:.2f}'.format(amount)
I know that it return this format: $39.99 but I don't know what each sign means. Could someone explain?
the $ is outside of formatted string placeholder
{: is the beginning of the formatted string
.2f is the fixed number of places after the decimal
} end of your place holder
i find it always fun to experiment to test a function or a module, you can also format the date, output, lots of other stuff... all in that lovely reference page

Sorting characters of a string 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 7 years ago.
Improve this question
How to sort the letters in a string alphabetically in Python without using join()? Using join() we can do this:
def sort_string(a)
return ''.join(sorted(a))
Is there a way to sort string without using join()?
Your solution is correct as strings are immutable in python. So, it's impossible to change (in your case - sort) an existing string. You have to create new one (you do it with join() call).
Also, good notes about sorting letters in string in python can be found here: How to sort the letters in a string alphabetically in Python

Categories