Linked Questions

Score of 2728
16 answers
4172337 views

I want to get a new string from the third character to the end of the string, e.g. myString[2:end]. If omitting the second part means 'to the end', and if you omit the first part, does it start from ...
Score of 93
7 answers
23390 views

list = ["a", "b", "c", "d"] print(list[3]) # Number 3 is "d" print(list[-4]) # Number -4 is "a"
Score of 187
7 answers
1103308 views

I'm trying to take a file that looks like this: AAA x 111 AAB x 111 AAA x 112 AAC x 123 ... And use a dictionary so that the output looks like this {AAA: ['111', '112'], AAB: ['111'], AAC: [123], ...}...
Score of 178
3 answers
383974 views

I'm new to Python. I see : used in list indices especially when it's associated with function calls. Python 2.7 documentation suggests that lists.append translates to a[len(a):] = [x]. Why does one ...
Score of 108
2 answers
367849 views

I cannot understand this. I have seen this in people's code. But cannot figure out what it does. This is in Python. str(int(a[::-1]))
Score of 111
2 answers
202069 views

I want to parse something like: list = ['A', 'B', 'C'] And using list slicing have it return to me everything but the first index: ['B', 'C'] I tried list[:-1], list[::-1], list[0:-1], etc. What I ...
Score of 62
4 answers
253098 views

Working on a python assignment and was curious as to what [:-1] means in the context of the following code: instructions = f.readline()[:-1] Have searched on here on S.O. and on Google but to no ...
Score of 32
9 answers
80288 views

I am a newbie to Python and have come across the following example in my book that is not explained very well. Here is my print out from the interpreter: >>> s = 'spam' >>> s[:-1] '...
Score of 37
6 answers
133761 views

Possible Duplicate: Good Primer for Python Slice Notation I've been reading over some sample code lately and I've read quite a few websites but I just can't seem to get the query right to give me ...
Score of 33
5 answers
164028 views

I'm trying to port some Python code to C, but I came across this line and I can't figure out what it means: if message.startswith('<stream:stream'): message = message[:-1] + ' />' I ...
Score of 24
6 answers
136870 views

I was trying to understand Kadane's algorithm from Wikipedia, when I found this: def max_subarray(A): max_ending_here = max_so_far = A[0] for x in A[1:]: max_ending_here = max(x, ...
Score of 41
1 answer
198261 views

What does the line del taglist[:] do in the code below? import urllib from bs4 import BeautifulSoup taglist=list() url=raw_input("Enter URL: ") count=int(raw_input("Enter count:")) position=int(...
Score of 20
1 answer
68069 views

I am plotting a graph using plt.plot using information found online. However, I do not know what the y[:,0] means: plt.plot(t, y[:,0], label= 'active Mos') Similarly, I see y[:,1] a lot too... ...
Score of 15
3 answers
150611 views

I have a list of unicode values. To the best of my knowledge I can use list[starting location:length to select] to select a range of values from a list, right? I have a list of 78 unicode values, ...
Score of 29
2 answers
20595 views

The extended slice syntax in python has been explained to me as "a[n:m:k] returns every kth element from n to m". This gives me a good idea what to expect when k is positive. But I'm lost on how to ...

15 30 50 per page
1
2 3 4 5
111