How to insert an int at a specific index in a list ?

Oct 24, 2012 at 6:24pm

How to insert an int at a specific index in a list ?

Title pretty much says it all.
Say I have a list of 10 zeroes and I want to add a one at the 2nd position,
how would I do that ?

Also, any recommendations on a elegant way to generate a list of zeros ?

Thank you,
George

#64912
Oct 24, 2012 at 7:04pm

If the number of places is known, why not just have a message box with that many zeros in it? At any rate, this is a completely non-general solution to the stated problem:

– Pasted Max Patch, click to expand. –
#234032
Oct 24, 2012 at 7:08pm

Hi,

is this what you mean?

– Pasted Max Patch, click to expand. –

Cheers,
Ádám

P.S. My solution assumes that you work with 0-based list counting, so the ’2nd element’ in this example is the third item of the list.

#234033
Oct 24, 2012 at 7:51pm

I think you could work with a jit.matrix object. That would be the easiest way to manipulate a list of numbers.
Another way of creating a list of zeros is to use zl group with uzi sending 0 as a message.

#234034
Oct 24, 2012 at 11:11pm

A slice-less version :)

– Pasted Max Patch, click to expand. –
#234035
Oct 25, 2012 at 9:34am

You can also use this feature of [zl nth] -which I like.

Richard

– Pasted Max Patch, click to expand. –
#234036
Oct 25, 2012 at 3:15pm

Wow, thanks a lot guys! This is very cool!

#234037

You must be logged in to reply to this topic.