Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to compare each char from two strings in python?

I have leetcode question

Input: jewels = "aA", stones = "aAAbbbb"
Output: 3

and capital letters a and A are different types.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Input: jewels = "z", stones = "ZZ"
Output: 0

So how would count in python. I think zip is not a good choice because it pairs index by index.

>Solution :

Not sure if I understood the problem correctly but if you are trying to see how many common characters the two strings have and also how many occurrences of each you could do it like so:

len([i for i in stones if i in jewels])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading