Finding Patterns in strings without regex | Python Tutorial

Опубликовано: 04 Июль 2021
на канале: namit
437
8

Tutorial For Python Problem Solving

QUESTION:
You're given two non-empty strings. The first one is a pattern consisting of only "x" s and/or "y" s; the other one is a normal string of alphanumeric characters. Write a function that checks whether the normal string matches the pattern.


A string S0 is said to match a pattern if replacing all "x" s in the pattern with some non-empty substring S1 of S0 and replacing all "y" s in the pattern with some non-empty substring S2 of S0 yields the same string S0.

If the input string doesn't match the input pattern, the function should return an empty array; otherwise, it should return an array holding the strings S1 and S2 represent "x" and "y" in the normal string, in that order. If the pattern doesn't contain any "x" s or "y" s, the respective letter should be represented by an empty string in the final array that you return.


You can assume that there will never be more than one pair of strings S1 and S2 appropriately represent "x" and "y" in the normal string.

Input Format
pattern = "xxyxxy"

string = "gogopowerrangergogopowerranger"

Output Format
["go", "powerranger"]

Sample Testcase #0
Testcase Input
xxyxxy
gogopowerrangergogopowerranger
Testcase Output
go powerranger


Code Link:
https://code.sololearn.com/c9a7A20A6A19


Follow me on sololearn: https://www.sololearn.com/profile/181...


На этой странице сайта вы можете посмотреть видео онлайн Finding Patterns in strings without regex | Python Tutorial длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь namit 04 Июль 2021, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 437 раз и оно понравилось 8 зрителям. Приятного просмотра!