Error in while loop code for packing items

MRAB python at mrabarnett.plus.com
Thu Aug 18 10:00:45 EDT 2016


On 2016-08-18 14:10, GP wrote:
> On Thursday, August 18, 2016 at 5:59:43 PM UTC+5:30, Peter Otten wrote:
>> GP wrote:
>>
[snip]
>>
>> However, when you really want to remove all items you instead assign a new
>> empty list
>>
>> for item in items:
>>     print(item)
>> items = []
>
>
> Thanks Peter for the information. It helps to find the source of error .
>
> What I wanted was to remove the items that was packed so that the code  can check for the next items that match the criteria and then pack those and delete them  and keep on repeating until all the items are packed. This is where I am getting stuck.
>
The simplest way is to iterate over the list of items and, for each 
item, if it fits the shelf, put it on the shelf, else put it into a list 
of the 'unused' items.

At the end of a pass, you'll have a shelf of items and a list of the 
remaining items.




More information about the Python-list mailing list