Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

list vs. dict : how to rearrange indices after removing element?

Status
Not open for further replies.

AdriansonCrusoe

Technical User
Oct 30, 2011
9
ES
With lists, when you delete one element the indices are rearranged, e.g. deleting "zero" from "zero one two" gives lindex 0 = "one". Is that possible with [dict create 0 "zero" 1 "one" ...] ? ( something like PHP's array_splice )
 
Hi

Not sure what is your goal and what you want with the [tt]dict[/tt].

If you just want to keep the original indices unchanged after deleting an element, use an [tt]array[/tt] :
Code:
[blue]%[/blue] array set whatever { 0 zero 1 one 2 two }

[blue]%[/blue] array get whatever
0 zero 1 one 2 two

[blue]%[/blue] array unset whatever 0

[blue]%[/blue] array get whatever
1 one 2 two


Feherke.
 
Thanks for replying :) It's quite the opposite, I need the keys to readjust themselves like list indices do, so if you delete key x then key x+1 becomes key x, and key x+2 becomes key x+1, etc.
 
Hi

Got you. At least, got your goal.

Sorry, I know no way to do that directly.

Maybe if you describe the task itself, someone will be know an alternative.


Feherke.
 
Yeap, I thought it wasn't possible right out-of-the-box, but I was hoping I could spare myself nested lists and custom code. XD
Thank you anyway :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top