remove. In that case, you can remove the item by using the value of that item.
To do that you have to fill in the parenthesis of the remove() method with the
value.
officeitems = ['printer', 'scanner', 'fan', 'table', 'chair', 'computer system', 'table
lights']
print(officeitems)
officeitems.remove('scanner')
print(officeitems)
officeitems.remove('table')
print(officeitems)
= RESTART: C:/Users/saifia computers/Desktop/sample.py
['printer', 'scanner', 'fan', 'table', 'chair', 'computer system', 'table lights']
['printer', 'fan', 'table', 'chair', 'computer system', 'table lights']
['printer', 'fan', 'chair', 'computer system', 'table lights']
>>>
Just like you used the popped value later on in the code, you can also use the
removed value from the item.
officeitems = ['printer', 'scanner', 'fan', 'table', 'chair', 'computer system', 'table
lights']
print(officeitems)
removeditem = 'scanner'
officeitems.remove(removeditem)
print("I have sold the " + removeditem.title() + "
because it was not adding
the desired value to the office.")
= RESTART: C:/Users/saifia computers/Desktop/sample.py
['printer', 'scanner', 'fan', 'table', 'chair', 'computer system', 'table lights']
I have sold the Scanner because it was not adding
the desired value to the
office.
>>>
List Organization
More often when you create lists, they flow in a kind of unpredictable order.
You cannot always control the order in which the
users provide data to the
program. However, you can bring that information into perfect order later on.
It may happen more often than you want to make the information presentable.
This is the reason you should bring it into perfect order. There are several
ways by which you can order lists in Python.
Do'stlaringiz bilan baham: