Advertisement
elena1234

Lambda , map and percentage discount in Python

Mar 1st, 2023 (edited)
845
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | Source Code | 0 0
  1. ''' We need to apply a discount for customers who purchased more than 500 dollars worth of product – they’re starting to complain it hasn’t been applied. They need to get 10% off on their orders.
  2.  
  3. Can you quickly apply a discount? Store the new prices in a list called discounted_subtotals. '''
  4.  
  5. subtotals = [15.98, 899.97, 799.97, 117.96, 5.99, 599.99]
  6. discounted_subtotals = list(map(lambda x: x - (x*0.1) if x > 500  else x, subtotals))
  7. discounted_subtotals
  8.  
  9.  
  10. # OR
  11. discounted_subtotals_ = list(map(lambda x: x * 0.9 if x > 500  else x, subtotals))
  12. discounted_subtotals_
  13.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement