ds_using_list.py 575 B

1234567891011121314151617181920212223
  1. # This is my shopping list
  2. shoplist = ['apple', 'mango', 'carrot', 'banana']
  3. print('I have', len(shoplist), 'items to purchase.')
  4. print('These items are:', end=' ')
  5. for item in shoplist:
  6. print(item, end=' ')
  7. print('\nI also have to buy rice.')
  8. shoplist.append('rice')
  9. print('My shopping list is now', shoplist)
  10. print('I will sort my list now')
  11. shoplist.sort()
  12. print('Sorted shopping list is', shoplist)
  13. print('The first item I will buy is', shoplist[0])
  14. olditem = shoplist[0]
  15. del shoplist[0]
  16. print('I bought the', olditem)
  17. print('My shopping list is now', shoplist)