Delete list item

I thought the 1st script would fail and it does as its trying to iterate over a list and delete part of it at same time

So, I wrote the 2nd one and that works as expected because it works backwards down the list

But why does the the 3rd one work?

ProjectName=delList

I think, it has to do with it's one dimensionality. Don't now why this works...but this one doesn't work >>>

untitled script pic

delList script pic (2)
but
delList script pic (1)

delList script pic (3)

Hey there are hyperblocks why should you do this?
test=(keep items{<item(1 v)of item != 0>} of test)

Aah - I see why now - just lucky that it works in the simple case :slight_smile:

But it doesn't work properly in this one of course as it skips over testing the second 0

image

Oh, you can just make it iterate backwards to get it to work? When I do this I decrease the index by 1 when an element gets removed.

Pamela says:Deleting something when iterating over it is opening a can of worms.

image

untitled script pic (8)

I was giving a solution for searching all rows and columns of a matrix, if it being a matrix was necessary

Why you don't use KEEP in this case ?

image

I created a version of the for each block that always checks the length of the list, and whenever you delete an item, it makes the # variable doesn't skip deleted items. It changes it's number by the amount of deleted items. I don't know if you understand
me, but if you look at the script, I think you'll understand.

(The keep items reporter is to create an entirely new list, so when you delete an item, it doesn't delete it from the temp list variable too)

i sed that 2

image

Yes, but if i SET mylist to keep from mylist : mylist contains the result!

yeah, but if you're doing something like this,

[scratchblocks]
(#) for each (item) of (list) {
if <(#) = [0]::> {
delete (#) of (list)
} else {
say (item)
} :: control
} :: list
[/scratchblocks]

your script won't work.

also, the part you quoted, I was talking about my script)

CANT U JUST LISTEN TO PAMELA?
SHE SEZ DONT TRY TO MODIFY A ARRAY WHEN ITERATING OVER IT!!!

what's the problem with that? I honestly don't see any problem with modifying an array when iterating over it. You can do whatever you like in programming. People can do it if they like, and I have created a block that allows for people to do it.

Hmmmmp!
Don't you see a bug in here?
When your for got to update the length?

uh, my script updates the length of (temp list) if the length is different from the original list.