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...
In questa pagina del sito puoi guardare il video online Finding Patterns in strings without regex | Python Tutorial della durata di ore minuti seconda in buona qualità , che l'utente ha caricato namit 04 luglio 2021, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 437 volte e gli è piaciuto 8 spettatori. Buona visione!