Removing an Item from a List (by value): различия между версиями
(Added "See Also" section.) |
Patarakin (обсуждение | вклад) |
||
(не показаны 3 промежуточные версии этого же участника) | |||
Строка 1: | Строка 1: | ||
{{ | {{Scripting Tutorials | ||
|Description=Как удалить элемент из списка по значению этого элемента, а не по его индексу? В статье рассматривается пример на Scratch | |||
|Field_of_knowledge=Информатика, Психология | |||
|FieldActivity=Computational Thinker | |||
|Возрастная категория=9 | |||
|Environment=Scratch | |||
}} | |||
Using the [[delete () of () (block)|delete () of ()]] [[list]] [[block]], one can remove a specified item from a [[list]] based on its numerical value in the list, but there is no individual block that removes an item (or multiple items) which contains a specified [[string]] from a list. This tutorial will show how to '''remove an item from a list based on the string''' stored within the item. | Using the [[delete () of () (block)|delete () of ()]] [[list]] [[block]], one can remove a specified item from a [[list]] based on its numerical value in the list, but there is no individual block that removes an item (or multiple items) which contains a specified [[string]] from a list. This tutorial will show how to '''remove an item from a list based on the string''' stored within the item. | ||
Строка 11: | Строка 17: | ||
The following script can be used to program this. | The following script can be used to program this. | ||
<scratchblocks> | <scratchblocks> | ||
delete (item # of [ruby] in [gems v]) of [gems v] | delete (item # of [ruby] in [gems v]) of [gems v] | ||
Строка 27: | Строка 33: | ||
This script repeats deleting the first item that is "ruby" until it deletes all of the "ruby" items. | This script repeats deleting the first item that is "ruby" until it deletes all of the "ruby" items. | ||
[[Category:Scripting Tutorials]] | [[Category:Scripting Tutorials]] |
Текущая версия на 10:23, 19 мая 2023
Описание | Как удалить элемент из списка по значению этого элемента, а не по его индексу? В статье рассматривается пример на Scratch |
---|---|
Область знаний | Информатика, Психология |
Область использования (ISTE) | Computational Thinker |
Возрастная категория | 9
|
Поясняющее видео | |
Близкие рецепту понятия | |
Среды и средства для приготовления рецепта: | Scratch |
Using the delete () of () list block, one can remove a specified item from a list based on its numerical value in the list, but there is no individual block that removes an item (or multiple items) which contains a specified string from a list. This tutorial will show how to remove an item from a list based on the string stored within the item.
Project Situations
There could be a number of purposes why one would need to remove an item from a list based on its value (or string). The following are possible situations:
- A list contains of items found, and the items are in random order based on when they were discovered; later, one item is given away, and the list must remove that specified item based on its name from the list.
- A grocery list being broken down as items are bought.
Code
The following script can be used to program this.
delete (item # of [ruby] in [gems v]) of [gems v]
This script will find the index of the first "ruby" and delete that item.
This second method removes all items that are the specified string instead of just the first:
repeat until <not <[gems v] contains [ruby]> > delete (item # of [ruby] in [gems v]) of [gems v] end
This script repeats deleting the first item that is "ruby" until it deletes all of the "ruby" items.