daily pastebin goal
61%
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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']
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top