Questions tagged [slice]

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. Please use the tags "object-slicing" for the slicing problem in C++ and "program-slicing" for the analysis technique.

A slice is a representation of a part of a sequence (including, but not limited to, lists, arrays and strings), 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.

Further reading:

5087 questions
2
votes
1 answer

dataframe column slices excluding specific columns

How will i slice pandas dataframe with large number of columns, where I do not wish to select specific and non-sequentially positioned columns? One option is to drop the specific columns, but can i do something like: df =…
Siraj S.
  • 2,601
  • 2
  • 24
  • 37
2
votes
1 answer

How can I generalise a function that accepts an `&[T]` so that I can still invoke it with a bytestring literal?

I started off with a function a bit like this (playground): fn find (src: &[T], index: usize) -> T { // more complex algorithm, involving src goes here src[index] } pub fn main() { let x = b"abc"; assert_eq!(b'b', find(x,…
Peter Hall
  • 36,534
  • 10
  • 79
  • 144
2
votes
7 answers

Python Slice a List Using a List of Multiple Tuples

I have a list of numbers that I would like to slice the range of numbers that is given from a list of multiple tuples. For example, I have a list that looks like: my_list = [ 5, 8, 3, 0, 0, 1, 3, 4, 8, 13, 0, 0, 0, 0, 21, 34, 25, 91, 61, 0, 0,] I…
Kate
  • 67
  • 1
  • 5
2
votes
1 answer

PHP mongodb new driver slice(init,limit) nested array

I have this collection in MongoDB {"name": "x", password: "x" recipes: [{title: eggs, ...},{title: "pizza" ...}], name: "y", password: "y" recipes: [...]} I am working with the new php mongodriver 1.0 I would like get all recipes of users filters…
Lucke
  • 299
  • 3
  • 12
2
votes
1 answer

Selecting data in parenthesis

I have a list of movies in a csv file, 100rows x 1column that looks like this: 1. Mulholland Drive (David Lynch, 2001) I'm trying to get rid of the number in the front, put the title, director, and year in each column. I did: rank =…
matt
  • 25
  • 3
2
votes
2 answers

Determining the last file chunk

I'm trying to setup a file upload through rest for large files. The function below is taking care of chunking but I need to be able to recognize the last chunk because my rest call changes to /finishUpload() in order to commit the save. Right now…
Batman
  • 4,075
  • 12
  • 59
  • 122
2
votes
2 answers

Golang: print string array in an unique way

I want a function func format(s []string) string such that for two string slices s1 and s2, if reflect.DeepEqual(s1, s2) == false, then format(s1) != format(s2). If I simply use fmt.Sprint, slices ["a", "b", "c"] and ["a b", "c"] are all printed as…
Ted
  • 788
  • 1
  • 8
  • 17
2
votes
3 answers

Slicing list with different string matching conditions

I'd like to slice a list of strings based on substrings possibly contained into its elements: l = ['Some long text', 'often begins', ' with ', 'impenetrable fog ', 'which ends', ' somewhere further'] startIndex = [u for u, v in enumerate(l) if…
2
votes
1 answer

pandas datetime slicing: junkdf.ix['2015-08-03':'2015-08-06'] not working

junkdf: rev dtime 2015-08-03 20.45 2015-08-04 -2.57 2015-08-05 12.53 2015-08-06 -8.16 2015-08-07 -4.41 junkdf.reset_index().to_dict('rec') [{'dtime': datetime.date(2015, 8, 3), 'rev': 20.45}, {'dtime': datetime.date(2015, 8,…
codingknob
  • 8,950
  • 18
  • 77
  • 113
2
votes
4 answers

How to return the maximum element of a slice of a list

I am trying to simplify this function at his maximum, how can I do? def eleMax(items, start=0, end=None): if end is None: end = len(items) return max(items[start:end]) I thought of def eleMax(items, start=0, end=-1): return…
Natim
  • 15,199
  • 21
  • 80
  • 140
2
votes
1 answer

Converting between Vec and &str

I have a Vec I need to read as &str. Right now I've found two ways to do it, both of which leave me unhappy. // Quite complex for something this simple str::from_utf8(buffer.into_iter().map(|c| c as u8).collect::>().as_slice()) and //…
2
votes
1 answer

Slicing list inside a method (Python 3)

I have a method like the following: def slice_list(my_list, slice_point): my_list = my_list[:slice_point] print("Inside method: ", my_list) return I have a test for it like the following: if __name__ == "__main__": my_list =…
tomasyany
  • 965
  • 2
  • 11
  • 31
2
votes
0 answers

Unexpected behavior in Pandas timestamp slicing

I have a DataFrame like In [29]: data = pd.DataFrame(np.random.random((72000,3)), columns=list('uvw'), index=pd.date_range('2013-11-08 10:00:00', periods=72000, freq='50L')) In [30]: print(data[['u', 'v', 'w']]) …
TomCho
  • 2,928
  • 3
  • 21
  • 64
2
votes
1 answer

Combination Sum III on Leetcode

The leetcode question is: Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers. Example 1: Input: k = 3, n =…
hong carl
  • 55
  • 5
2
votes
1 answer

Updating Panel slice

I need to update a panel slice with some values retreated from a dataframe. Even if I don't get back any error it doesn't work. What it's wrong ? df = pd.DataFrame(np.random.rand(10, 4), columns=['sd', 'ed', 'sbc',…
Cursore
  • 33
  • 1
  • 5
1 2 3
99
100