Skip to content
Advertisement

How to find and calculate common letters between words in pandas

I have a dataset with some words in it and I want to compare 2 columns and count common letters between them.

For e.g I have:

JavaScript

And I want to have smth like that:

JavaScript

Advertisement

Answer

You can use a list comprehension with help of itertools.takewhile:

JavaScript

output:

JavaScript

NB. the logic was no fully clear, so here this stops as soon as there is a mistmatch

If you want to continue after a mistmatch (which doesn’t seems to fit the “pizza” example):

JavaScript

output:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement