Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- test = DictionaryVariable.get('2')
- print test
- def FindPrice(dictionary, idlist):
- price = 0.00
- for id in idlist:
- price + float(dictionary.get(id))
- return price
- Prices = FindPrice(DictionaryVariable, IDListVariable)
- print Prices
- def FindPrice(dictionary, idlist):
- Price = sum(float(dictionary.get(x,0)) for x in idlist)
- return Price
- Prices = FindPrice(DictionaryVariable, FunctionThatMakesListofIDs('FileToGetIDsFrom.xml'))
- print Prices
- >>> d = {'2': '150.99', '3': '99.50', '15': '5.07'}
- >>> d = dict((int(k),float(v)) for k, v in d.iteritems())
- >>> d
- {2: 150.99000000000001, 3: 99.5, 15: 5.0700000000000003}
- >>> dic={'2': '150.99', '3': '99.50', '15': '5.07'}
- >>> items= ['2', '2', '3']
- >>> sum(float(dic.get(x,0)) for x in items) #pass 0 to get in case id is not there
- 401.48
- get(...)
- D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.
Add Comment
Please, Sign In to add comment