Top "Slice" questions

A slice is a representation of a part of a sequence, usually defined by a reference to the underlying sequence, an index giving the starting position, a length or end position, and optionally a "stride" or "step" value.

Extract elements of list at odd positions

So I want to create a list which is a sublist of some existing list. For example, L = [1, 2, 3, 4, 5, 6, 7], I want …

python list slice
How to get the last element of a slice?

What is the Go way for extracting the last element of a slice? var slice []int slice = append(slice, 2) slice = …

go slice
How to search for an element in a golang slice

I have a slice of structs. type Config struct { Key string Value string } // I form a slice of the above …

go struct slice
how to get the last part of a string before a certain character?

I am trying to print the last part of a string before a certain character. I'm not quite sure whether …

python string python-2.7 split slice
How to slice an array in Bash

Looking the "Array" section in the bash(1) man page, I didn't find a way to slice an array. So I …

arrays bash slice
Understanding string reversal via slicing

I was looking for a way to print a string backwards, and after a quick search on google, I found …

python string slice
How do you clear a slice in Go?

What is the appropriate way to clear a slice in Go? Here's what I've found in the go forums: // test.…

arrays go slice
Why can't I duplicate a slice with `copy()`?

I need to make a copy of a slice in Go and reading the docs there is a copy function …

go slice
How to query MultiIndex index columns values in pandas

Code example: In [171]: A = np.array([1.1, 1.1, 3.3, 3.3, 5.5, 6.6]) In [172]: B = np.array([111, 222, 222, 333, 333, 777]) In [173]: C = randint(10, 99, 6) In [174]: df = pd.DataFrame(zip(A, B, …

python pandas indexing slice multi-index
How to find out element position in slice?

How does one determine the position of an element present in slice? I need something like the following: type intSlice []…

position go slice