Guest User

Untitled

a guest
Aug 10th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. x = {'qqq': 2, 'www': 3}
  2.  
  3. def lex_flatten(record):
  4. assert record
  5. assert isinstance(record, dict)
  6. result = list()
  7. for key, val in record.items():
  8. assert isinstance(key, str)
  9. assert isinstance(val, int)
  10. result.extend([key] * val)
  11. return result
  12.  
  13. lex_flatten(x)
  14. #['qqq', 'qqq', 'www', 'www', 'www']
Add Comment
Please, Sign In to add comment