Guest User

Untitled

a guest
Jan 17th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. test = DictionaryVariable.get('2')
  2. print test
  3.  
  4. def FindPrice(dictionary, idlist):
  5. price = 0.00
  6. for id in idlist:
  7. price + float(dictionary.get(id))
  8. return price
  9.  
  10. Prices = FindPrice(DictionaryVariable, IDListVariable)
  11. print Prices
  12.  
  13. def FindPrice(dictionary, idlist):
  14. Price = sum(float(dictionary.get(x,0)) for x in idlist)
  15. return Price
  16. Prices = FindPrice(DictionaryVariable, FunctionThatMakesListofIDs('FileToGetIDsFrom.xml'))
  17. print Prices
  18.  
  19. >>> d = {'2': '150.99', '3': '99.50', '15': '5.07'}
  20. >>> d = dict((int(k),float(v)) for k, v in d.iteritems())
  21. >>> d
  22. {2: 150.99000000000001, 3: 99.5, 15: 5.0700000000000003}
  23.  
  24. >>> dic={'2': '150.99', '3': '99.50', '15': '5.07'}
  25. >>> items= ['2', '2', '3']
  26. >>> sum(float(dic.get(x,0)) for x in items) #pass 0 to get in case id is not there
  27. 401.48
  28.  
  29. get(...)
  30. D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.
Add Comment
Please, Sign In to add comment