Re: [Tutor] SLICING

2018-06-15 Thread Steven D'Aprano
On Fri, Jun 15, 2018 at 04:57:47PM +0300, kenneth yashim wrote: > please im new to python or any other programming language. please i want to > understand how slicing works > > [start,stop,step] > > >>> 'abc'[0:3] > 'abc' > > >>>'abc'[0:-1] > 'ab' > > why does 'abc'[2:1] or 'abc'[2:1] prin

Re: [Tutor] SLICING

2018-06-15 Thread Alan Gauld via Tutor
On 15/06/18 14:57, kenneth yashim wrote: > please im new to python or any other programming language. please i want to > understand how slicing works > > [start,stop,step] > 'abc'[0:3] > 'abc' > 'abc'[0:-1] > 'ab' > > why does 'abc'[2:1] or 'abc'[2:1] print ' ' instead of 'c'???

Re: [Tutor] Slicing Tuples

2010-12-12 Thread John Russell
Thanks to all for your answers, especially those that went into detail about why its done in that way. As far as whether this is actually addressed in the book, as far as I can tell by going a few pages forward, it does not. In fact, after the code there's a how it works section which only added t

Re: [Tutor] Slicing Tuples

2010-12-11 Thread David Hutto
So, in essence, that would be redefining(in Python) basic division of grammatical structures(splices)? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Slicing Tuples

2010-12-11 Thread Steven D'Aprano
John Russell wrote: So, my question is this, and I realize that this is *very* basic - what is going on with the last element? Why is it returning one less than I think it logically should. Am I missing something here? There is not much of an explanation in the book, but I would really like to u

Re: [Tutor] Slicing Tuples

2010-12-11 Thread Hugo Arts
On Sat, Dec 11, 2010 at 5:25 PM, John Russell wrote: > Last night I started working through a book (Beginning Python: Using Python > 2.6 and Python 3.1)  I bought to learn Python, and there is an example in it > that doesn't make sense to me. > There is an example on slicing sequences that goes li

Re: [Tutor] slicing a string

2010-09-08 Thread Sandip Bhattacharya
On Thu, Sep 9, 2010 at 11:34 AM, Evert Rol wrote: > Read > http://docs.python.org/library/stdtypes.html#sequence-types-str-unicode-list-tuple-buffer-xrange > , note 5 (about one "page" down), which explicitly says "If i or j are > omitted or None, they become “end” values (which end depends on the

Re: [Tutor] slicing a string

2010-09-08 Thread Evert Rol
>> But remember that you can make it simpler if you simply don't specify >> the start and end points: >> > 'hello'[::-1] >> 'olleh' >> > > While I know that idiom works, I haven't really found an explanation > as to *why* it works that way. > > For a string S: > * Using range, you need ran

Re: [Tutor] slicing a string

2010-09-08 Thread Sandip Bhattacharya
On Tue, Sep 7, 2010 at 1:49 PM, Roel Schroeven wrote: > > But remember that you can make it simpler if you simply don't specify > the start and end points: > 'hello'[::-1] > 'olleh' > While I know that idiom works, I haven't really found an explanation as to *why* it works that way. For a s

Re: [Tutor] slicing a string

2010-09-07 Thread lists
>>> Assuming that mytext is "test", I've found that mytext[-1:-4:-1] >>> doesn't work (as I expected it to) but that mytext[::-1] does. >>> >>> While that's fine, I just wondered why mytext[-1:-4:-1] doesn't >>> work? >> >> It does work. >> But remember that slices give you the first item to one le

Re: [Tutor] slicing a string

2010-09-07 Thread Roel Schroeven
Op 2010-09-07 0:43, Alan Gauld schreef: > > "lists" wrote > >> Assuming that mytext is "test", I've found that mytext[-1:-4:-1] >> doesn't work (as I expected it to) but that mytext[::-1] does. >> >> While that's fine, I just wondered why mytext[-1:-4:-1] doesn't >> work? > > It does work. > B

Re: [Tutor] slicing a string

2010-09-06 Thread Andre Engels
On Tue, Sep 7, 2010 at 12:44 AM, lists wrote: >>> Assuming that mytext is "test", I've found that mytext[-1:-4:-1] >>> doesn't work (as I expected it to) but that mytext[::-1] does. >>> >>> While that's fine, I just wondered why mytext[-1:-4:-1] doesn't work? >> >> How does it not "work"? What did

Re: [Tutor] slicing a string

2010-09-06 Thread Steven D'Aprano
On Tue, 7 Sep 2010 08:14:59 am lists wrote: > Hi guys, > > Continuing my Python learning, I came across an exercise which asks > me to take a string and reverse it. > > I understand that there is a function to do this i.e mytext.reverse() You understand wrong :) There is a function reversed() whi

Re: [Tutor] slicing a string

2010-09-06 Thread lists
>>> Assuming that mytext is "test", I've found that mytext[-1:-4:-1] >>> doesn't work (as I expected it to) but that mytext[::-1] does. >>> >>> While that's fine, I just wondered why mytext[-1:-4:-1] doesn't work? >> >> How does it not "work"? What did you expect to happen? What did it do >> inste

Re: [Tutor] slicing a string

2010-09-06 Thread lists
>> Assuming that mytext is "test", I've found that mytext[-1:-4:-1] >> doesn't work (as I expected it to) but that mytext[::-1] does. >> >> While that's fine, I just wondered why mytext[-1:-4:-1] doesn't work? > > How does it not "work"? What did you expect to happen? What did it do instead? > > Gr

Re: [Tutor] slicing a string

2010-09-06 Thread Alan Gauld
"lists" wrote Assuming that mytext is "test", I've found that mytext[-1:-4:-1] doesn't work (as I expected it to) but that mytext[::-1] does. While that's fine, I just wondered why mytext[-1:-4:-1] doesn't work? It does work. But remember that slices give you the first item to one less tha

Re: [Tutor] slicing a string

2010-09-06 Thread Sander Sweers
On 7 September 2010 00:14, lists wrote: > Assuming that mytext is "test", I've found that mytext[-1:-4:-1] > doesn't work (as I expected it to) but that mytext[::-1] does. > > While that's fine, I just wondered why mytext[-1:-4:-1] doesn't work? How does it not "work"? What did you expect to happ

Re: [Tutor] slicing nested lists/dicts/tuples

2005-07-02 Thread Brian van den Broek
Luis N said unto the world upon 02/07/2005 07:51: > On 7/2/05, Luis N <[EMAIL PROTECTED]> wrote: > > Umm, sorry, I meant: > > d[desc[x]] = exec("""'vw[%s].desc[%s]'""" % (r,x )) > > > > > > __

Re: [Tutor] slicing nested lists/dicts/tuples

2005-07-02 Thread Luis N
On 7/2/05, Luis N <[EMAIL PROTECTED]> wrote: Umm, sorry, I meant: d[desc[x]] = exec("""'vw[%s].desc[%s]'""" % (r,x )) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] slicing nested lists/dicts/tuples

2005-07-02 Thread Luis N
Hi, Yes, sorry I haven't posted to the list in a while. I should have been more specific. I'm writing a simple contact database, using metakit as the backend. Thank you for pointing out that what I was trying to do was easier than I believed. Here's some code. db = metakit.storage('c:/addy.mk'

Re: [Tutor] slicing nested lists/dicts/tuples

2005-06-28 Thread Reed L. O'Brien
Reed L. O'Brien wrote: >Luis N wrote: > > > >>Hi, >> >> >> >l > > >>[{'last': 'Bar', 'first': 'Foo'}, {'last': 'Bar', 'first': 'Foo'}, >>{'last': 'Bar', 'first': 'Foo'}, {'last': 'Bar', 'first': 'Foo'}] >> >> >>This is how I imagine it: >> >>for i in l: >>for j in l

Re: [Tutor] slicing nested lists/dicts/tuples

2005-06-28 Thread Reed L. O'Brien
Luis N wrote: > Hi, > > >>> l > [{'last': 'Bar', 'first': 'Foo'}, {'last': 'Bar', 'first': 'Foo'}, > {'last': 'Bar', 'first': 'Foo'}, {'last': 'Bar', 'first': 'Foo'}] > > > This is how I imagine it: > > for i in l: > for j in l[i]: > for k in l[i][j]: > print k.get('first')

Re: [Tutor] slicing nested lists/dicts/tuples

2005-06-28 Thread Brian van den Broek
Luis N said unto the world upon 28/06/2005 15:25: > Hi, > > l > > [{'last': 'Bar', 'first': 'Foo'}, {'last': 'Bar', 'first': 'Foo'}, {'last': > 'Bar', 'first': 'Foo'}, {'last': 'Bar', 'first': 'Foo'}] > > > This is how I imagine it: > > for i in l: > for j in l[i]: > for k in l[i][j]: >