>> I recently faced a similar issue doing something like this:
>>
>> data_out = []
>> for i in range(len(data_in)):
>> data_out.append([])
>
> Another way to write this is
> data_out = [[]] * len(data_in)
...if you're willing to put up with this side-effect:
>>> data_in = ran
On Fri, 11 Jan 2008 22:18:22 GMT Neil Hodgson <[EMAIL PROTECTED]> wrote:
> Marty:
> > I recently faced a similar issue doing something like this:
> > data_out = []
> > for i in range(len(data_in)):
> > data_out.append([])
>
> Another way to write this is
> data_out = [[]] * le
Marty:
> I recently faced a similar issue doing something like this:
>
> data_out = []
> for i in range(len(data_in)):
> data_out.append([])
Another way to write this is
data_out = [[]] * len(data_in)
Neil
--
http://mail.python.org/mailman/listinfo/python-list
Fredrik Lundh <[EMAIL PROTECTED]> writes:
> (and if you use sane naming conventions, the risk for collisions is
> near zero as well).
I haven't felt that way, I'm always worried about clobbering something
by leaking a variable. Maybe collisions don't really happen much, but
it's always seemed cle
Paul Rubin wrote:
> it just seems way too obscure though. Python style seems to favor
> spewing extra variables around.
that's because (local) variables have near-zero cost, and zero overhead.
use as many as you want, and reuse them as often as you want to.
(and if you use sane naming conven
On Fri, 11 Jan 2008 01:48:43 -0500 Marty <[EMAIL PROTECTED]> wrote:
> Mike Meyer wrote:
> >> This caused me to wonder why Python does not have a "foreach" statement
> >> (and
> >> also why has it not come up in this thread)? I realize the topic has
> >> probably
> >> been beaten to death in ea
On Jan 10, 10:36 pm, Marty <[EMAIL PROTECTED]> wrote:
> Hrvoje Niksic wrote:
> > Mike Meyer <[EMAIL PROTECTED]> writes:
>
> >> It sounds to me like your counter variable actually has meaning,
>
> > It depends how the code is written. In the example such as:
>
> > for meaningless_variable in xrange
Mike Meyer wrote:
> On Thu, 10 Jan 2008 22:36:56 -0500 Marty <[EMAIL PROTECTED]> wrote:
>> I recently faced a similar issue doing something like this:
>>
>> data_out = []
>> for i in range(len(data_in)):
>> data_out.append([])
>
> More succinctly:
>
> data_out = []
> for _
On Thu, 10 Jan 2008 22:36:56 -0500, Marty wrote:
> I recently faced a similar issue doing something like this:
>
> data_out = []
> for i in range(len(data_in)):
> data_out.append([])
>
> This caused me to wonder why Python does not have a "foreach" statement
> (and also why has it
Mike Meyer <[EMAIL PROTECTED]> writes:
> data_out = [[] for _ in data_in]
> ...
> But I'm curious - what's the difference between the "foreach" you have
> in mind and the standard python "for"?
The "for" loop, like the list comprehension, pollutes the namespace
with an index variable that's not us
erik gartz <[EMAIL PROTECTED]> writes:
> The loop performs some actions with web services. The particular
> iteration I'm on isn't important to me. It is only important that I
> attempt the web services that number of times. If I succeed I
> obviously break out of the loop and the containing functi
On Jan 10, 10:36 pm, Marty <[EMAIL PROTECTED]> wrote:
> Hrvoje Niksic wrote:
> > Mike Meyer <[EMAIL PROTECTED]> writes:
>
> >> It sounds to me like your counter variable actually has meaning,
>
> > It depends how the code is written. In the example such as:
>
> > for meaningless_variable in xrange
On Thu, 10 Jan 2008 22:36:56 -0500 Marty <[EMAIL PROTECTED]> wrote:
> I recently faced a similar issue doing something like this:
>
> data_out = []
> for i in range(len(data_in)):
> data_out.append([])
More succinctly:
data_out = []
for _ in data_in:
data_out.append([])
Or, a
> On Behalf Of Marty
> I recently faced a similar issue doing something like this:
>
> data_out = []
> for i in range(len(data_in)):
> data_out.append([])
>
> This caused me to wonder why Python does not have a "foreach"
> statement (and also why has it not come up in this thread
Hrvoje Niksic wrote:
> Mike Meyer <[EMAIL PROTECTED]> writes:
>
>> It sounds to me like your counter variable actually has meaning,
>
> It depends how the code is written. In the example such as:
>
> for meaningless_variable in xrange(number_of_attempts):
> ...
>
> the loop variable really
On Jan 9, 10:55 pm, Ben Finney <[EMAIL PROTECTED]>
wrote:
> erik gartz <[EMAIL PROTECTED]> writes:
> > The loop performs some actions with web services. The particular
> > iteration I'm on isn't important to me. It is only important that I
> > attempt the web services that number of times. If I suc
On Thu, 10 Jan 2008 08:42:16 +0100 Hrvoje Niksic <[EMAIL PROTECTED]> wrote:
> Mike Meyer <[EMAIL PROTECTED]> writes:
> > It sounds to me like your counter variable actually has meaning,
> It depends how the code is written. In the example such as:
>
> for meaningless_variable in xrange(number_of_
erik gartz <[EMAIL PROTECTED]> wrote:
> Hi. I'd like to be able to write a loop such as:
> for i in range(10):
> pass
> but without the i variable. The reason for this is I'm using pylint
> and it complains about the unused variable i. I can achieve the above
> with more lines of code like:
>
Mike Meyer <[EMAIL PROTECTED]> writes:
> It sounds to me like your counter variable actually has meaning,
It depends how the code is written. In the example such as:
for meaningless_variable in xrange(number_of_attempts):
...
the loop variable really has no meaning. Rewriting this code on
> Unfortunately, I don't *think* I can shut the
> warning for that line or function off, only for the entire file.
> Pylint gives you a rating of your quality of code which I think is
wrong :)
# pylint: disable-msg=X will only impact the current line!
$ cat -n dummy.py
1 for i in range(2):
On Wed, 9 Jan 2008 18:49:36 -0800 (PST) erik gartz <[EMAIL PROTECTED]> wrote:
> The loop performs some actions with web services. The particular
> iteration I'm on isn't important to me. It is only important that I
> attempt the web services that number of times. If I succeed I
> obviously break ou
erik gartz <[EMAIL PROTECTED]> writes:
> The loop performs some actions with web services. The particular
> iteration I'm on isn't important to me. It is only important that I
> attempt the web services that number of times. If I succeed I
> obviously break out of the loop and the containing funct
On Wed, 09 Jan 2008 14:25:36 -0800, erik gartz wrote:
> Hi. I'd like to be able to write a loop such as: for i in range(10):
> pass
> but without the i variable. The reason for this is I'm using pylint and
> it complains about the unused variable i. I can achieve the above with
> more lines of
On Jan 9, 9:49 pm, erik gartz <[EMAIL PROTECTED]> wrote:
> The loop performs some actions with web services. The particular
> iteration I'm on isn't important to me. It is only important that I
> attempt the web services that number of times. If I succeed I
> obviously break out of the loop and the
On Jan 9, 8:35 pm, Dan Sommers <[EMAIL PROTECTED]> wrote:
> On Wed, 09 Jan 2008 14:25:36 -0800, erik gartz wrote:
> > Hi. I'd like to be able to write a loop such as:
> > for i in range(10):
> > pass
> > but without the i variable. The reason for this is I'm using pylint and
> > it complains ab
On Wed, 09 Jan 2008 14:25:36 -0800, erik gartz wrote:
> Hi. I'd like to be able to write a loop such as:
> for i in range(10):
> pass
> but without the i variable. The reason for this is I'm using pylint and
> it complains about the unused variable i ...
What does that loop do? (Not the loop
On Jan 10, 10:00 am, Tim Chase <[EMAIL PROTECTED]> wrote:
> >> Hi. I'd like to be able to write a loop such as:
> >> for i in range(10):
> >> pass
> >> but without the i variable. The reason for this is I'm using pylint
> >> and it complains about the unused variable i.
>
> > if a computer tell
erik gartz schrieb:
> Hi. I'd like to be able to write a loop such as:
> for i in range(10):
> pass
> but without the i variable. The reason for this is I'm using pylint
> and it complains about the unused variable i.
Pychecker won't complain if you rename 'i' to '_', IIRC:
for _ in range(10)
>> Hi. I'd like to be able to write a loop such as:
>> for i in range(10):
>> pass
>> but without the i variable. The reason for this is I'm using pylint
>> and it complains about the unused variable i.
>
> if a computer tells you to do something stupid, it's often better to
> find a way to t
erik gartz schrieb:
> Hi. I'd like to be able to write a loop such as:
> for i in range(10):
> pass
> but without the i variable. The reason for this is I'm using pylint
> and it complains about the unused variable i. I can achieve the above
> with more lines of code like:
> i = 0
> while (i !=
erik gartz wrote:
> Hi. I'd like to be able to write a loop such as:
> for i in range(10):
> pass
> but without the i variable. The reason for this is I'm using pylint
> and it complains about the unused variable i.
if a computer tells you to do something stupid, it's often better to
find a
31 matches
Mail list logo