fork download
  1. import re
  2. text='''Consumer Price Index:
  3. +0.2% in Sep 2020
  4.  
  5. Unemployment Rate:
  6. +7.9% in Sep 2020
  7.  
  8. Producer Price Index:
  9. +0.4% in Sep 2020
  10.  
  11. Employment Cost Index:
  12. +0.5% in 2nd Qtr of 2020
  13.  
  14. Productivity:
  15. +10.1% in 2nd Qtr of 2020
  16.  
  17. Import Price Index:
  18. +0.3% in Sep 2020
  19.  
  20. Export Price Index:
  21. +0.6% in Sep 2020'''
  22. print( re.findall(r'(\S.*):\n\s*(\+?\d[\d.]*%)\s+in\s+(.*)', text) )
Success #stdin #stdout 0.02s 9392KB
stdin
Standard input is empty
stdout
[('Consumer Price Index', '+0.2%', 'Sep 2020'), ('Unemployment Rate', '+7.9%', 'Sep 2020'), ('Producer Price Index', '+0.4%', 'Sep 2020'), ('Employment Cost Index', '+0.5%', '2nd Qtr of 2020'), ('Productivity', '+10.1%', '2nd Qtr of 2020'), ('Import Price Index', '+0.3%', 'Sep 2020'), ('Export Price Index', '+0.6%', 'Sep 2020')]