Advertisement
VSZM

Untitled

Jan 22nd, 2019
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. The popular command-line shell bash expands strings that include braces with lists of strings inside of them. For example:
  2.  
  3. $ echo _{a,b,c}{1,2}
  4. _a1 _a2 _b1 _b2 _c1 _c2
  5.  
  6. $ echo hello{world,kitty}
  7. helloworld hellokitty
  8.  
  9. Problem: Write a function to do (simplified) bash-style brace expansion.
  10.  
  11. _{a,b,c}{1,2}!
  12.  
  13. _a1!
  14. _a{1,2}, _a
  15.  
  16. Tehát a lényeg, hogy bejön egy string, amiben vannak kapcsos zárójelek. Egy kapcsoszárójel pár között vesszővel elválasztott stringek vannak.
  17. Ezeket a stringeket kell behelyettesíteni a kapcsoszárójelek közötti rész helyére, és így képezni stringeket.
  18.  
  19. Példák:
  20. "hello{world,kitty}" -> ["helloworld", "hellokitty"]
  21. "_{a,b,c}{1,2}!" -> ["_a1!", "_a2!", "_b1!", "_b2!", "_c1!", "_c2!"]
  22. "_{a,b,c}{1,2}" -> ["_a1", "_a2", "_b1", "_b2", "_c1", "_c2"]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement