Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #43672 > unrolled thread
| Started by | idkfaidkfaidkfa@gmail.com |
|---|---|
| First post | 2013-04-16 08:20 -0700 |
| Last post | 2013-04-16 17:16 +0000 |
| Articles | 8 — 6 participants |
Back to article view | Back to comp.lang.python
Newbie questions on Python idkfaidkfaidkfa@gmail.com - 2013-04-16 08:20 -0700
Re: Newbie questions on Python Chris Angelico <rosuav@gmail.com> - 2013-04-17 01:30 +1000
Re: Newbie questions on Python Walter Hurry <walterhurry@lavabit.com> - 2013-04-16 21:40 +0000
Re: Newbie questions on Python Chris Angelico <rosuav@gmail.com> - 2013-04-17 07:53 +1000
Re: Newbie questions on Python Matt Jones <matt.walker.jones@gmail.com> - 2013-04-16 10:33 -0500
Re: Newbie questions on Python Neil Cerutti <neilc@norwich.edu> - 2013-04-16 15:41 +0000
Re: Newbie questions on Python Lele Gaifax <lele@metapensiero.it> - 2013-04-16 18:06 +0200
Re: Newbie questions on Python Neil Cerutti <neilc@norwich.edu> - 2013-04-16 17:16 +0000
| From | idkfaidkfaidkfa@gmail.com |
|---|---|
| Date | 2013-04-16 08:20 -0700 |
| Subject | Newbie questions on Python |
| Message-ID | <a6562e3b-29af-4953-bc8b-49fa634d1be7@googlegroups.com> |
Hi all, i'm programming in python for the first time (usually i use C as programming language). I don't understand these results: >>> a=[1,2,3,4,5] >>> a[:-1] [1, 2, 3, 4] >>> a[::-1] [5, 4, 3, 2, 1] >>> a[2::-1] [3, 2, 1] what does a[2::-1] means? Thanks
[toc] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-04-17 01:30 +1000 |
| Message-ID | <mailman.666.1366126206.3114.python-list@python.org> |
| In reply to | #43672 |
On Wed, Apr 17, 2013 at 1:20 AM, <idkfaidkfaidkfa@gmail.com> wrote: > Hi all, > i'm programming in python for the first time (usually i use C as programming language). I don't understand these results: > >>>> a=[1,2,3,4,5] >>>> a[:-1] > [1, 2, 3, 4] >>>> a[::-1] > [5, 4, 3, 2, 1] >>>> a[2::-1] > [3, 2, 1] > > what does a[2::-1] means? That's taking a slice. This page has something to say on the subject: http://docs.python.org/3.3/tutorial/introduction.html By the way, regarding your email address: there are no cheat codes in Python... either that, or Python *is* a cheat code. :) ChrisA [[ VERY HAPPY CODING ADDED ]]
[toc] | [prev] | [next] | [standalone]
| From | Walter Hurry <walterhurry@lavabit.com> |
|---|---|
| Date | 2013-04-16 21:40 +0000 |
| Message-ID | <kkkggq$9vj$2@news.albasani.net> |
| In reply to | #43673 |
On Wed, 17 Apr 2013 01:30:03 +1000, Chris Angelico wrote: > By the way, regarding your email address: there are no cheat codes in > Python ROFLMAO. Incidentally, my son used to use IDDQD rather than IDKFA. I of course spurned all such, since I preferred to do it the hard way. Thus I was Doomed.
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-04-17 07:53 +1000 |
| Message-ID | <mailman.692.1366149703.3114.python-list@python.org> |
| In reply to | #43705 |
On Wed, Apr 17, 2013 at 7:40 AM, Walter Hurry <walterhurry@lavabit.com> wrote: > On Wed, 17 Apr 2013 01:30:03 +1000, Chris Angelico wrote: > >> By the way, regarding your email address: there are no cheat codes in >> Python > > ROFLMAO. Incidentally, my son used to use IDDQD rather than IDKFA. > > I of course spurned all such, since I preferred to do it the hard way. > Thus I was Doomed. I'd sometimes use IDDQD/IDFA (no K) and then see how quickly I could blitz the levels, with proper navigation. There's something inherently fun about blasting through everything with the rocket launcher. Mind you, I was really cheap, so I never bought Doom... and was just playing through the demo over and over. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Matt Jones <matt.walker.jones@gmail.com> |
|---|---|
| Date | 2013-04-16 10:33 -0500 |
| Message-ID | <mailman.667.1366126460.3114.python-list@python.org> |
| In reply to | #43672 |
[Multipart message — attachments visible in raw view] — view raw
When slicing: l[start:end:step] In your example of "a[2::-1]" you are reversing the list by using a step of -1, then you are slicing at index 2 (third element). *Matt Jones* On Tue, Apr 16, 2013 at 10:30 AM, Chris Angelico <rosuav@gmail.com> wrote: > On Wed, Apr 17, 2013 at 1:20 AM, <idkfaidkfaidkfa@gmail.com> wrote: > > Hi all, > > i'm programming in python for the first time (usually i use C as > programming language). I don't understand these results: > > > >>>> a=[1,2,3,4,5] > >>>> a[:-1] > > [1, 2, 3, 4] > >>>> a[::-1] > > [5, 4, 3, 2, 1] > >>>> a[2::-1] > > [3, 2, 1] > > > > what does a[2::-1] means? > > That's taking a slice. This page has something to say on the subject: > > http://docs.python.org/3.3/tutorial/introduction.html > > By the way, regarding your email address: there are no cheat codes in > Python... either that, or Python *is* a cheat code. :) > > ChrisA > [[ VERY HAPPY CODING ADDED ]] > -- > http://mail.python.org/mailman/listinfo/python-list >
[toc] | [prev] | [next] | [standalone]
| From | Neil Cerutti <neilc@norwich.edu> |
|---|---|
| Date | 2013-04-16 15:41 +0000 |
| Message-ID | <at59opFg036U1@mid.individual.net> |
| In reply to | #43672 |
On 2013-04-16, idkfaidkfaidkfa@gmail.com <idkfaidkfaidkfa@gmail.com> wrote:
> Hi all,
> i'm programming in python for the first time (usually i use C as programming language). I don't understand these results:
>
>>>> a=[1,2,3,4,5]
>>>> a[:-1]
> [1, 2, 3, 4]
>>>> a[::-1]
> [5, 4, 3, 2, 1]
>>>> a[2::-1]
> [3, 2, 1]
The third item is the "step". The default value is 1. If you
provide a negative step, your slice will be in reverse. So you
are getting item 2 through 0 in reverse order in your result
slice.
Imagine something like the following for loop taking place
somewhere:
for (int i = 2; i <= 0; --i) {
fprintf(a[i]);
}
--
Neil Cerutti
[toc] | [prev] | [next] | [standalone]
| From | Lele Gaifax <lele@metapensiero.it> |
|---|---|
| Date | 2013-04-16 18:06 +0200 |
| Message-ID | <mailman.671.1366128396.3114.python-list@python.org> |
| In reply to | #43676 |
Neil Cerutti <neilc@norwich.edu> writes:
> Imagine something like the following for loop taking place
> somewhere:
>
> for (int i = 2; i <= 0; --i) {
> fprintf(a[i]);
> }
Neil most probably meant
for (int i = 2; i >= 0; --i) {
fprintf(a[i]);
}
where "fprintf" is actually a fictitious "do_something" function.
ciao, lele.
--
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
lele@metapensiero.it | -- Fortunato Depero, 1929.
[toc] | [prev] | [next] | [standalone]
| From | Neil Cerutti <neilc@norwich.edu> |
|---|---|
| Date | 2013-04-16 17:16 +0000 |
| Message-ID | <at5fb1Fhg41U1@mid.individual.net> |
| In reply to | #43679 |
On 2013-04-16, Lele Gaifax <lele@metapensiero.it> wrote:
> Neil Cerutti <neilc@norwich.edu> writes:
>
>> Imagine something like the following for loop taking place
>> somewhere:
>>
>> for (int i = 2; i <= 0; --i) {
>> fprintf(a[i]);
>> }
>
> Neil most probably meant
>
> for (int i = 2; i >= 0; --i) {
> fprintf(a[i]);
> }
>
> where "fprintf" is actually a fictitious "do_something" function.
>
> ciao, lele.
Thanks for the correction.
--
Neil Cerutti
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web