Skip to content

Commit cb9eb5f

Browse files
committed
Using list
1 parent fc6eb8d commit cb9eb5f

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

using_list.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/python3.1
2+
# Filename : using_list.py
3+
4+
# This is my shopping list
5+
shoplist = ['apple', 'mango', 'carrot', 'banana']
6+
7+
print('I have', len(shoplist), 'items to purchase.')
8+
print('These items are:')
9+
for i in range(0, len(shoplist)):
10+
print('shoplist[', i, '] = ', shoplist[i])
11+
12+
print('\nI also have to buy rice.')
13+
shoplist.append('rice')
14+
print('My shopping list is now', shoplist)
15+
16+
print('I will sort my list now')
17+
shoplist.sort()
18+
print('Sorted shopping list is ', shoplist)
19+
20+
print('The first item I will buy is', shoplist[0])
21+
olditem = shoplist[0]
22+
del(shoplist[0])
23+
print('I bought the', olditem)
24+
print('My shopping list is now', shoplist)

0 commit comments

Comments
 (0)