How do you remove from the list?

Good afternoon. Is it possible to remove from the list all links containing words like "expires"
for example I have a list like this

https://site.ru/expires=37046973
https://site.ru/expires=12046712
https://site.ru/expires=19063984
https://site.ru/extended=1548689
https://site.ru/extended=11486889
https://site.ru/extended=18486889

With these blocks I can remove numbers before links, but how can I completely remove links containing certain words?

Edit

Wrong code as @ABG explained , I don't delete it so people will be able to understand the error . :sweat_smile:

For each items in list (list of links)
if items contain expires
Then
Delete item from list (list of links) index of item in list (list of links)

Look near the bottom of the list blocks pallette for the advanced list block that creates a new list from an old one based on a selection test.

You want to test logical not of text contains the thing you want to exclude.

1 Like

It's true , I forget them , always :joy::joy:

That approach requires the For Each Number block, counting down from length of list by -1 in order to get the indices for the testing and removal by position.

Beware of the collapse of index numbers you would get if you traveled upwards while deleting items.
That would skip items.

Oh my God, like a newbie :man_facepalming:t2:.

Hi, I never studed coding or some programming language, but I like to learn , try and test.

I don't know the code inside the block but probably appinventor is ahead of normal people :joy: and know the most common errors made by people like me who don't have a solid foundation in computer science.
The code I used in the example works fine, probably because is a short list or probably because the block itself works in the way you showed us.
Maybe you or some power users know why it works.
Here the two codes I tried on the right side your hint ( I hope :smile:)

1 Like

Both approaches "work", but the one on the right is safer, because it avoids reliance on undefined behavior.

The undefined behavior on the left relates to the For Each In List block.
How does it work when the list it is traversing crumbles under its feet?
Did it make a local copy of the list before it started?
Is it like a mountain climber, with pitons (pointers) driven into the next item on the list to save him from a landslide?

The AI2 docs don't say. I know AI2 lists are linked lists, based on my Ouroborous trick, but I don't know if they are singly or doubly linked lists.

It's best to avoid dangerous reliance on guesses, and to stick to well defined behaviors.

1 Like

did you check the complete list after removing the items?
My guess is, item 6@ is still in the list, because you did not remove items as suggested... and for the other removed items you were lucky...

therefore as @ABG already explained

Taifun

Thanks both @Taifun and @ABG to reply. As I said my code is wrong , didactically and for a beginner who want to learn how to write a right code.
Also I understand well what @ABG said to me and how index moving while code run.

yes I checked the complete list

I'm not lucky, I tried a lot of sequence

I was expecting an error but nothing , so I made another test and I saw how items go up when delete block run. The for each block count correctly 11 items even if they changed places. I will try other tests :man_facepalming:t2:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.