fork download
  1. from contextlib import contextmanager
  2. import re
  3.  
  4. @contextmanager
  5. def assign_match(regex, string):
  6. match = re.match(regex, string)
  7. if match:
  8. yield match.groups()
  9.  
  10. for i in range(3):
  11. with assign_match('(abc)(def)', 'ABCDEF') as a:
  12. # for a in assign_match('(abc)(def)', 'abcdef'):
  13. print(a)
  14. continue
  15. print(i)
  16.  
Runtime error #stdin #stdout 0.04s 5956KB
stdin
Standard input is empty
stdout
Standard output is empty