inventory = ["flour", "milk", "sugar", "eggs", "vanilla", "salt"]
print(inventory)
print(inventory[1])
inventory.append("banana")
inventory.insert(2, "grapes")
inventory.remove("eggs")
print(inventory)
print(inventory.pop(5))
print(inventory)
inventory.pop(5)
['flour', 'milk', 'sugar', 'eggs', 'vanilla', 'salt']
milk
['flour', 'milk', 'grapes', 'sugar', 'vanilla', 'salt', 'banana']
salt
['flour', 'milk', 'grapes', 'sugar', 'vanilla', 'banana']
'banana'
names = ["ravi", "sushant", "shriya"]
names2 = ["john", "sophie", "gayathri","kate"]
namelengths = []
for name in names:
namelength = len(name)
namelengths.append(namelength)
print(namelengths)
def itemlengths(itemlist):
itemlengthlist = []
for item in itemlist:
itemlengthlist.append(len(item))
return itemlengthlist
print(itemlengths(names))
print(itemlengths(names2))
[4, 7, 6]
[4, 7, 6]
[4, 6, 8, 4]