Splitting a string by list of indices

s=”long string that I want to split up” indices = [0,5,12,17] parts = [s[i:j] for i,j in zip(indices, indices[1:]+[None])] returns [‘long ‘, ‘string ‘, ‘that ‘, ‘I want to split up’] which you can print using: print ‘\n’.join(parts) Another possibility (without copying indices) would be: s=”long string that I want to split up” indices = … Read more

Is a JavaScript array index a string or an integer?

Formally, all property names are strings. That means that array-like numeric property names really aren’t any different from any other property names. If you check step 6 in the relevant part of the spec, you’ll see that property accessor expressions are always coerced to strings before looking up the property. That process is followed (formally) … Read more

Access lapply index names inside FUN

Unfortunately, lapply only gives you the elements of the vector you pass it. The usual work-around is to pass it the names or indices of the vector instead of the vector itself. But note that you can always pass in extra arguments to the function, so the following works: x <- list(a=11,b=12,c=13) # Changed to … Read more

tech