Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #29822 > unrolled thread
| Started by | jimbo1qaz <jimmyli1528@gmail.com> |
|---|---|
| First post | 2012-09-23 09:36 -0700 |
| Last post | 2012-09-25 12:20 +0100 |
| Articles | 20 on this page of 44 — 17 participants |
Back to article view | Back to comp.lang.python
For Counter Variable jimbo1qaz <jimmyli1528@gmail.com> - 2012-09-23 09:36 -0700
Re: For Counter Variable Rodrick Brown <rodrick.brown@gmail.com> - 2012-09-23 12:45 -0400
Re: For Counter Variable Chris Angelico <rosuav@gmail.com> - 2012-09-24 02:52 +1000
Re: For Counter Variable jimbo1qaz <jimmyli1528@gmail.com> - 2012-09-23 10:45 -0700
Re: For Counter Variable Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-23 22:54 +0000
Re: For Counter Variable Tim Chase <python.list@tim.thechases.com> - 2012-09-23 18:29 -0500
Re: For Counter Variable Tim Chase <python.list@tim.thechases.com> - 2012-09-23 19:05 -0500
Re: For Counter Variable Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-09-24 02:03 +0100
RE: For Counter Variable "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-09-27 17:34 +0000
Re: For Counter Variable Ethan Furman <ethan@stoneleaf.us> - 2012-09-24 15:09 -0700
Re: For Counter Variable Dwight Hutto <dwightdhutto@gmail.com> - 2012-09-24 18:26 -0400
Re: For Counter Variable Dwight Hutto <dwightdhutto@gmail.com> - 2012-09-24 18:58 -0400
Re: For Counter Variable alex23 <wuwei23@gmail.com> - 2012-09-24 16:33 -0700
Re: For Counter Variable Dwight Hutto <dwightdhutto@gmail.com> - 2012-09-24 19:49 -0400
Re: For Counter Variable alex23 <wuwei23@gmail.com> - 2012-09-24 16:58 -0700
Re: For Counter Variable Dwight Hutto <dwightdhutto@gmail.com> - 2012-09-24 20:17 -0400
Re: For Counter Variable alex23 <wuwei23@gmail.com> - 2012-09-24 17:19 -0700
Re: For Counter Variable Dwight Hutto <dwightdhutto@gmail.com> - 2012-09-24 20:25 -0400
Re: For Counter Variable "Littlefield, Tyler" <tyler@tysdomain.com> - 2012-09-24 18:32 -0600
Re: For Counter Variable Dwight Hutto <dwightdhutto@gmail.com> - 2012-09-24 20:45 -0400
Re: For Counter Variable Dwight Hutto <dwightdhutto@gmail.com> - 2012-09-24 20:50 -0400
Re: For Counter Variable Paul Rubin <no.email@nospam.invalid> - 2012-09-24 18:10 -0700
Re: For Counter Variable Dwight Hutto <dwightdhutto@gmail.com> - 2012-09-24 21:32 -0400
Re: For Counter Variable Chris Angelico <rosuav@gmail.com> - 2012-09-25 17:55 +1000
Re: For Counter Variable Dwight Hutto <dwightdhutto@gmail.com> - 2012-09-24 21:13 -0400
Re: For Counter Variable Ramchandra Apte <maniandram01@gmail.com> - 2012-09-29 06:41 -0700
Re: For Counter Variable Ramchandra Apte <maniandram01@gmail.com> - 2012-09-29 06:41 -0700
Re: For Counter Variable Dwight Hutto <dwightdhutto@gmail.com> - 2012-09-24 19:50 -0400
Re: For Counter Variable Dwight Hutto <dwightdhutto@gmail.com> - 2012-09-24 19:39 -0400
Re: For Counter Variable alex23 <wuwei23@gmail.com> - 2012-09-24 16:48 -0700
Re: For Counter Variable Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-09-25 07:53 +0200
Re: For Counter Variable Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-25 07:46 +0000
Re: For Counter Variable Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-09-25 08:59 +0100
Re: For Counter Variable wxjmfauth@gmail.com - 2012-09-25 02:32 -0700
Re: For Counter Variable Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-09-25 10:46 +0100
Re: For Counter Variable Chris Rebert <clp2@rebertia.com> - 2012-09-25 02:53 -0700
Re: For Counter Variable Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-09-25 11:16 +0100
Re: For Counter Variable Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-25 14:19 +0000
Re: For Counter Variable Chris Angelico <rosuav@gmail.com> - 2012-09-26 00:38 +1000
Re: For Counter Variable Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-09-25 11:54 -0400
Re: For Counter Variable wxjmfauth@gmail.com - 2012-09-25 02:32 -0700
(non sequitur) Re: For Counter Variable Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-09-25 11:51 -0400
Re: For Counter Variable Tim Chase <python.list@tim.thechases.com> - 2012-09-25 05:57 -0500
Re: For Counter Variable Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-09-25 12:20 +0100
Page 1 of 3 [1] 2 3 Next page →
| From | jimbo1qaz <jimmyli1528@gmail.com> |
|---|---|
| Date | 2012-09-23 09:36 -0700 |
| Subject | For Counter Variable |
| Message-ID | <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> |
Am I missing something obvious, or do I have to manually put in a counter in the for loops? That's a very basic request, but I couldn't find anything in the documentation.
[toc] | [next] | [standalone]
| From | Rodrick Brown <rodrick.brown@gmail.com> |
|---|---|
| Date | 2012-09-23 12:45 -0400 |
| Message-ID | <mailman.1125.1348418733.27098.python-list@python.org> |
| In reply to | #29822 |
On Sep 23, 2012, at 12:42 PM, jimbo1qaz <jimmyli1528@gmail.com> wrote: > Am I missing something obvious, or do I have to manually put in a counter in the for loops? That's a very basic request, but I couldn't find anything in the documentation. for idx in <list of elm>: print (idx) i.e.. for idx in range(10): print(idx) > -- > http://mail.python.org/mailman/listinfo/python-list
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2012-09-24 02:52 +1000 |
| Message-ID | <mailman.1128.1348419165.27098.python-list@python.org> |
| In reply to | #29822 |
On Mon, Sep 24, 2012 at 2:36 AM, jimbo1qaz <jimmyli1528@gmail.com> wrote:
> Am I missing something obvious, or do I have to manually put in a counter in the for loops? That's a very basic request, but I couldn't find anything in the documentation.
You mean, if you want the indices as well as the values? Try the
enumerate() function:
my_list = ["foo", "bar", "quux"]
for idx,val in enumerate(my_list):
print("Element "+str(idx)+" is: "+val)
ChrisA
[toc] | [prev] | [next] | [standalone]
| From | jimbo1qaz <jimmyli1528@gmail.com> |
|---|---|
| Date | 2012-09-23 10:45 -0700 |
| Message-ID | <a73d266f-fc5c-415f-8793-0078ab2436e7@googlegroups.com> |
| In reply to | #29822 |
On Sunday, September 23, 2012 9:36:19 AM UTC-7, jimbo1qaz wrote: > Am I missing something obvious, or do I have to manually put in a counter in the for loops? That's a very basic request, but I couldn't find anything in the documentation. Ya, they should really give a better way, but for now, enumerate works pretty well.
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2012-09-23 22:54 +0000 |
| Message-ID | <505f9311$0$1612$c3e8da3$76491128@news.astraweb.com> |
| In reply to | #29832 |
On Sun, 23 Sep 2012 10:45:53 -0700, jimbo1qaz wrote: > On Sunday, September 23, 2012 9:36:19 AM UTC-7, jimbo1qaz wrote: >> Am I missing something obvious, or do I have to manually put in a >> counter in the for loops? That's a very basic request, but I couldn't >> find anything in the documentation. > > Ya, they should really give a better way, but for now, enumerate works > pretty well. Define "a better way". What did you have in mind that would work better? -- Steven
[toc] | [prev] | [next] | [standalone]
| From | Tim Chase <python.list@tim.thechases.com> |
|---|---|
| Date | 2012-09-23 18:29 -0500 |
| Message-ID | <mailman.1166.1348442904.27098.python-list@python.org> |
| In reply to | #29871 |
On 09/23/12 17:54, Steven D'Aprano wrote: > On Sun, 23 Sep 2012 10:45:53 -0700, jimbo1qaz wrote: >> On Sunday, September 23, 2012 9:36:19 AM UTC-7, jimbo1qaz wrote: >>> Am I missing something obvious, or do I have to manually put in a >>> counter in the for loops? That's a very basic request, but I couldn't >>> find anything in the documentation. >> >> Ya, they should really give a better way, but for now, enumerate works >> pretty well. > > Define "a better way". What did you have in mind that would work better? I can only imagine jimbo1qaz intended "a more C-like way". blech. I **far** prefer The Python Way™. The vast majority of the time, I'm looping over some iterable where indices would only get in the way of readability. Tuple-unpacking the results of enumerate() is an elegant way of getting both the items+indices on the seldom occasion I need the index too (though I'm minorly miffed that enumerate()'s starting-offset wasn't back-ported into earlier 2.x versions and have had to code around it for 1-based indexing; either extra "+1"s or whip up my own simple enumerate() generator). -tkc
[toc] | [prev] | [next] | [standalone]
| From | Tim Chase <python.list@tim.thechases.com> |
|---|---|
| Date | 2012-09-23 19:05 -0500 |
| Message-ID | <mailman.1170.1348445056.27098.python-list@python.org> |
| In reply to | #29871 |
On 09/23/12 18:52, Alec Taylor wrote:
> You can always use a counter if you don't like our fancy for-each loops;
>
> foolist = [1,24,24,234,23,423,4]
> for i in xrange(len(foolist)):
> print foolist[i]
http://www.seas.upenn.edu/~lignos/py_antipatterns.html
The first one on the list of anti-patterns is doing exactly this.
Just don't. Ewww. Inefficient, ugly, and harder to read.
Part of learning to write in Python is, well, learning to write
*Python*, not {C,C++,Java,PHP}-in-Python.
-tkc
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2012-09-24 02:03 +0100 |
| Message-ID | <mailman.1173.1348448592.27098.python-list@python.org> |
| In reply to | #29871 |
On 24/09/2012 01:05, Tim Chase wrote:
> On 09/23/12 18:52, Alec Taylor wrote:
>> You can always use a counter if you don't like our fancy for-each loops;
>>
>> foolist = [1,24,24,234,23,423,4]
>> for i in xrange(len(foolist)):
>> print foolist[i]
>
> http://www.seas.upenn.edu/~lignos/py_antipatterns.html
>
> The first one on the list of anti-patterns is doing exactly this.
> Just don't. Ewww. Inefficient, ugly, and harder to read.
>
> Part of learning to write in Python is, well, learning to write
> *Python*, not {C,C++,Java,PHP}-in-Python.
>
> -tkc
>
Maybe my mind is rather more warped than I thought it was, but my first
impression was that foolist was a play on foolish.
I also like the anti-pattern on the link namely:-
for (index, value) in enumerate(alist):
print index, value
Fancy wasting time, money and effort typing those unnecessary round
brackets.
--
Cheers.
Mark Lawrence.
[toc] | [prev] | [next] | [standalone]
| From | "Prasad, Ramit" <ramit.prasad@jpmorgan.com> |
|---|---|
| Date | 2012-09-27 17:34 +0000 |
| Message-ID | <mailman.1504.1348767302.27098.python-list@python.org> |
| In reply to | #29871 |
Tim Chase wrote: > [snip] though I'm minorly miffed that > enumerate()'s starting-offset wasn't back-ported into earlier 2.x > versions and have had to code around it for 1-based indexing; either > extra "+1"s or whip up my own simple enumerate() generator). Starting offset is in Python 2.6, unless you meant earlier than 2.6. >>> for idx, x in enumerate( xrange(5), 10 ): ... print idx, x ... 10 0 11 1 12 2 13 3 14 4 This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email.
[toc] | [prev] | [next] | [standalone]
| From | Ethan Furman <ethan@stoneleaf.us> |
|---|---|
| Date | 2012-09-24 15:09 -0700 |
| Message-ID | <mailman.1223.1348524974.27098.python-list@python.org> |
| In reply to | #29832 |
jimbo1qaz wrote: > On Sunday, September 23, 2012 9:36:19 AM UTC-7, jimbo1qaz wrote: >> Am I missing something obvious, or do I have to manually put in a counter in the for loops? That's a very basic request, but I couldn't find anything in the documentation. > > Ya, they should really give a better way, but for now, enumerate works pretty well. ROFLOL!! I look forward to the day when you look back on that statement and think, "Wow, I've come a long way!" ~Ethan~
[toc] | [prev] | [next] | [standalone]
| From | Dwight Hutto <dwightdhutto@gmail.com> |
|---|---|
| Date | 2012-09-24 18:26 -0400 |
| Message-ID | <mailman.1225.1348525601.27098.python-list@python.org> |
| In reply to | #29832 |
On Mon, Sep 24, 2012 at 6:09 PM, Ethan Furman <ethan@stoneleaf.us> wrote: > jimbo1qaz wrote: >> >> On Sunday, September 23, 2012 9:36:19 AM UTC-7, jimbo1qaz wrote: >>> >>> Am I missing something obvious, or do I have to manually put in a counter >>> in the for loops? That's a very basic request, but I couldn't find anything >>> in the documentation. >> >> >> Ya, they should really give a better way, but for now, enumerate works >> pretty well. > > > ROFLOL!! > > I look forward to the day when you look back on that statement and think, > "Wow, I've come a long way!" > It's a function usage. Not to be too serious, there are usually simpler solutions, and built in functions. But you usually sticks with what works, and seems timely in return of data output -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com
[toc] | [prev] | [next] | [standalone]
| From | Dwight Hutto <dwightdhutto@gmail.com> |
|---|---|
| Date | 2012-09-24 18:58 -0400 |
| Message-ID | <mailman.1235.1348527537.27098.python-list@python.org> |
| In reply to | #29832 |
> *How* would one implement this better, more simply (for the user, not the > implementator) or in a more readable manner? Chose *any* one of those. Well if you're learning then the builtin might be more like how we answer students questions here, than those doing work. Write out the algorithmic function, and if you find one you can stuff a few parameters in fine, but you still now how to do it by yourself algorithmically. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com
[toc] | [prev] | [next] | [standalone]
| From | alex23 <wuwei23@gmail.com> |
|---|---|
| Date | 2012-09-24 16:33 -0700 |
| Message-ID | <19450a9a-5cd9-4197-b463-2f60445e8fb1@rj6g2000pbc.googlegroups.com> |
| In reply to | #29952 |
On Sep 25, 8:58 am, Dwight Hutto <dwightdhu...@gmail.com> wrote: > Well if you're learning then the builtin might be more like how we > answer students questions here, than those doing work. STOP SAYING THIS NONSENSE. Using a pre-defined function is _not_ the "student" approach. Rolling your own version of an existing function from scratch is _not_ the "professional" approach. If you're unable to realise this, then please stop dispensing advice here like you know something.
[toc] | [prev] | [next] | [standalone]
| From | Dwight Hutto <dwightdhutto@gmail.com> |
|---|---|
| Date | 2012-09-24 19:49 -0400 |
| Message-ID | <mailman.1244.1348530574.27098.python-list@python.org> |
| In reply to | #29960 |
>> Well if you're learning then the builtin might be more like how we >> answer students questions here, than those doing work. > > STOP SAYING THIS NONSENSE. > > Using a pre-defined function is _not_ the "student" approach. What are talking about, I suggested they roll there own in several responses this week. Rolling > your own version of an existing function from scratch is _not_ the > "professional" approach. Yes it is, if you don't know the builtin, and everyone has memory flaws. > If you're unable to realise this, then please stop dispensing advice > here like you know something. Dude, you know jack shit, so go shovel this bullshit somewhere else, where people aren't intelligent enough to read the rest of my posts -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com
[toc] | [prev] | [next] | [standalone]
| From | alex23 <wuwei23@gmail.com> |
|---|---|
| Date | 2012-09-24 16:58 -0700 |
| Message-ID | <59a70251-9e28-455f-a461-90cd4f29724a@r8g2000pbf.googlegroups.com> |
| In reply to | #29966 |
On Sep 25, 9:49 am, Dwight Hutto <dwightdhu...@gmail.com> wrote: > Rolling> your own version of an existing function from scratch is _not_ the > > "professional" approach. > > Yes it is, if you don't know the builtin, and everyone has memory flaws. Let me break this down for you in simple terms. Code represents experience. Code that is considered important enough to be in the standard library or as a built-in is something that encapsulates a _lot_ of experience over time. You in your naive approach to re-implement will _never capture that experience_. You'll miss the edge cases that were already addressed. You'll over- or under- extend the metaphor in ways the original doesn't. And the first thing any experienced programmer would do when they encountered your code is _refactor it to use the built-in_. > Dude, you know jack shit, so go shovel this bullshit somewhere else, > where people aren't intelligent enough to read the rest of my posts > CEO: http://www.hitwebdevelopment.com Is the animated GIF on your website under 60MB yet?
[toc] | [prev] | [next] | [standalone]
| From | Dwight Hutto <dwightdhutto@gmail.com> |
|---|---|
| Date | 2012-09-24 20:17 -0400 |
| Message-ID | <mailman.1250.1348532265.27098.python-list@python.org> |
| In reply to | #29970 |
> Is the animated GIF on your website under 60MB yet? yeah a command line called convert, and taking out a few jpegs used to convert, and I can reduce it to any size, what's the fucking point of that question other than ignorant rhetoric, that you know is easily fixable? -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com
[toc] | [prev] | [next] | [standalone]
| From | alex23 <wuwei23@gmail.com> |
|---|---|
| Date | 2012-09-24 17:19 -0700 |
| Message-ID | <26493369-8f41-456c-8a89-b4883e37d55c@k13g2000pbq.googlegroups.com> |
| In reply to | #29975 |
On Sep 25, 10:18 am, Dwight Hutto <dwightdhu...@gmail.com> wrote: > what's the fucking point of that question To highlight the vast gulf between what you think you are and what you actually produce.
[toc] | [prev] | [next] | [standalone]
| From | Dwight Hutto <dwightdhutto@gmail.com> |
|---|---|
| Date | 2012-09-24 20:25 -0400 |
| Message-ID | <mailman.1251.1348532738.27098.python-list@python.org> |
| In reply to | #29976 |
> To highlight the vast gulf between what you think you are and what you > actually produce. I produce working code, and if it works, then I don't just think...I know. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com
[toc] | [prev] | [next] | [standalone]
| From | "Littlefield, Tyler" <tyler@tysdomain.com> |
|---|---|
| Date | 2012-09-24 18:32 -0600 |
| Message-ID | <mailman.1254.1348533175.27098.python-list@python.org> |
| In reply to | #29976 |
On 9/24/2012 6:25 PM, Dwight Hutto wrote: >> To highlight the vast gulf between what you think you are and what you >> actually produce. > I produce working code, and if it works, then I don't just think...I know. > > Working code != good code. Just an observation. Also, I've noticed a vast differences between someone who can explain their answers as Alix has done on multiple threads you've replied to in the last 5 minutes, and someone who cobbles something together with "your variable isn't being shown right because there's no self.a," which actually really makes no sense at all. Just my $0.02. -- Take care, Ty http://tds-solutions.net The aspen project: a barebones light-weight mud engine: http://code.google.com/p/aspenmud He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave.
[toc] | [prev] | [next] | [standalone]
| From | Dwight Hutto <dwightdhutto@gmail.com> |
|---|---|
| Date | 2012-09-24 20:45 -0400 |
| Message-ID | <mailman.1255.1348533934.27098.python-list@python.org> |
| In reply to | #29976 |
>> Just my $0.02. > I'd estimate it at that value anyday. -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com
[toc] | [prev] | [next] | [standalone]
Page 1 of 3 [1] 2 3 Next page →
Back to top | Article view | comp.lang.python
csiph-web