Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. ````myInts = [ -3, 0, 4 ]
  2. ````myFloats = [ -2.2, 0.0, 1.1 ]
  3.  
  4. ```` 'aBool': myBools,
  5. ```` 'bInt': myInts,
  6. ```` 'cFloat': myFloats,
  7. ````}
  8.  
  9. Now, how do I get a list of dicts for all permutations of aBool, bInt and cFloat? Each list entry will be a dict. Each dict will have a unique set of values representing one permutation.
  10.  
  11. Expected:
  12.  
  13. ````myPermList = [
  14. ```` { 'aBool': True, 'bInt': -3, 'cFloat': -2.2 },
  15. ```` { 'aBool': True, 'bInt': -3, 'cFloat': 0.0 },
  16. ```` { 'aBool': True, 'bInt': -3, 'cFloat': 1.1 },
  17. ```` # ...
  18. ```` { 'aBool': False, 'bInt': 4, 'cFloat': -2.2 },
  19. ```` { 'aBool': False, 'bInt': 4, 'cFloat': 0.0 },
  20. ```` { 'aBool': False, 'bInt': 4, 'cFloat': 1.1 },
  21. ````]
  22.  
  23. I am having trouble trying to figure out if itertools.permutations can help me here and if so, how to set up the call.
  24.  
  25. The intended use of such a technique is to help automate testing of some other functions in a comprehensive and systematic way so that I can extend lists to include good as well as bad data to test both correct functionality in the case of good data and proper error handling in the case of bad data.
  26.  
  27. myBools, myInts and myFloats will represent tests for various data types that can be reused. These may be mixed in the future (i.e. test int and float data). But the code as written represents the simplest and most generic input and output data structures that I could think of.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement