How do we find a changing character between two unchanging strings?

Asked 2 years ago, Updated 2 years ago, 20 views

Title of the article Python Introduction Subheading

Title of the article It's hard. Subheading

Title of the article What could it be? Subheading

How do we find a string that changes from the string above, such as "Python Introduction," "Difficult," and "What is it?" The function is a non-writeable condition. Is there any way to do it with basic commands only?

python

2022-09-22 18:50

2 Answers

I think you can find the first four letters to the third letter from the back.

mystr = 'The title of the article is difficult Subhead
print(mystr[4:-3])


2022-09-22 18:50

The work of finding differences in random text has been widely studied and as a result, tools such as diff have been invented to compare two strings (or files). This uses an algorithm that applies editing distance (http://hsp1116.tistory.com/41), and there are many libraries that have already been implemented directly, so you can use them. Python has a difflib, so you can use this.


2022-09-22 18:50

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.