All Questions

1975
votes
27answers
986882 views

Understanding Python's slice notation

I need a good explanation (references are a plus) on Python's slice notation. To me, this notation needs a bit of picking up. It looks extremely powerful, but I haven't quite got my head around it...
409
votes
15answers
352111 views

Javascript fastest way to duplicate an Array - slice vs for loop

In order to duplicate an Array in Javascript, does anyone know (and maybe tested) if it's faster to use: Slice method: var dup_array = original_array.slice(); or For loop: for(var i = 0, len = o...
1289
votes
20answers
1096927 views

JavaScript chop/slice/trim off last character in string

I have a string, 12345.00, and I would like it to return 12345.0. I have looked at trim, but it looks like it is only trimming whitespace and slice which I don't see how this would work. Any suggesti...
18
votes
3answers
4404 views

What is the difference between slice assignment that slices the whole list and direct assignment?

I see at many places the use of slice assignment for lists. I am able to understand its use when used with (non-default) indices, but I am not able to understand its use like: a_list[:] = ['foo', 'ba...
518
votes
8answers
136251 views

What is the difference between String.slice and String.substring?

Does anyone know what the difference is between these two methods: String.slice String.substring
71
votes
2answers
299958 views

ValueError: setting an array element with a sequence

This Python code: import numpy as p def firstfunction(): UnFilteredDuringExSummaryOfMeansArray = [] MeanOutputHeader=['TestID','ConditionName','FilterType','RRMean','HRMean','dZdtMaxVoltageM...
70
votes
5answers
37999 views

Python: Implementing slicing in __getitem__

I am trying to implement slice functionality for a class I am making that creates a vector representation. I have this code so far, which I believe will properly implement the slice but whenever I do...
138
votes
7answers
48971 views

Explanation of [].slice.call in javascript?

I stumbled onto this neat shortcut for converting a DOM NodeList into a regular array, but I must admit, I don't completely understand how it works: [].slice.call(document.querySelectorAll('a'), 0) ...
31
votes
13answers
73415 views

reverse a string in Python

I was looking for a way to print a string backwards, and after a quick search on google, I found this method: Suppose 'a' is a string variable. This will return the 'a' string backwards: a[::-1] C...
127
votes
4answers
31787 views

How do you use the ellipsis slicing syntax in Python?

This came up in Hidden features of Python, but I can't see good documentation or examples that explain how the feature works.

Previous Next