Finding Patterns in strings without regex | Python Tutorial

Published: 04 July 2021
on channel: 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...


On this page of the site you can watch the video online Finding Patterns in strings without regex | Python Tutorial with a duration of hours minute second in good quality, which was uploaded by the user namit 04 July 2021, share the link with friends and acquaintances, this video has already been watched 437 times on youtube and it was liked by 8 viewers. Enjoy your viewing!