Properties
Category
English
Similar Topics
Statistics
Comments
12
Participants
5
Subscribers
0
Votes
1
Views
2482
Share
Answered
Terve.
What is the easiest way to delete n:th element from a list?
Mikko
- GeoGebra
- Help
- Partners
-
Contact us
- Feedback & Questions
- This email address is being protected from spambots. You need JavaScript enabled to view it.
- +43 677 6137 2693
© 2023 International GeoGebra Institute
HI
If you list1 have n elements
Take[liste1, 1, n] give you list1 minus the n:th element
Daniel
Thank you :o)
M
... exept it does not work.
I want to delete n:th object from the list, not everything after that.
M
Hi
Ok
your liste1 is the first list in which you want to remove the n:th element
make a slider n
liste2=Take [liste1,n,n]
liste3=liste1\liste2
Is there any easier way?
If you want to delete 4th in the list
list1 = {1, 2, 3, 4, 5, 6, 7, 8}
Union[Take[list1, 1, 3], Take[list1, 5, Length[list1]]]
list2 = {1, 2, 3, 5, 6, 7, 8}
Michael, make a command for that.
Mikko
Hi
More quickly
list=list1 \ Take[list1, n, n]
https://ggbm.at/552197
Actually this is a nice example that our students should learn some Set Theory in their maths education.
Mikko
there is already an Append[] command for Lists, why not make a Remove[] command for them too?
Furthermore, how do we remove the last element of a list without using another list?
What I do NOT want is:
list1 = {1,2,3,4,5}
list2 = list1\Last[list1]
What I want is:
list1 = list1 \ Last[list1]
but GeoGebra won't allow it because of circular definition, any thoughts :question:
Hi,
you can keep
list1Helper={1,2,3,4}
list1=RemoveUndefined[list1]
and then remove the last element from list1 using
SetValue[list1Helper,Length[list1],?]
and to append one element to list1
SetValue[list1Helper,Length[list1]+1,newElement]
Notes:
* Append command creates new list, unlike SetValue.
* SetValue lets you make the list one element longer.
* SetValue only works on free lists, therefore you have to use it (in the example above) on list1Helper and not list1 directly.
Cheers,
Zbynek
What if I want to push a number into a list, then pull it off, and then push another number into it, and then pull it off again(in scripts, of course, just like what I did in a ggb file about the tower of hanoi)?
Similar to kondr's method:
list1 = {4, 6, 7, 3, 2, 5, 7}
list2 = {1, 1, 1, 1, 1, ?, 1}
RemoveUndefined[list1 * list2]
You should be able to make a nice Tool from that :)
attached file is completed based on murkle's idea above, enjoy it :)
[Hint: Click on the bases of the towers to move discs]
https://ggbm.at/552577
Comments have been locked on this page!