Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #40249
| References | <118003ed-33f6-4d99-ac5e-99ec81921f45@googlegroups.com> <bsh60a-dn.ln1@satorlaser.homedns.org> |
|---|---|
| Date | 2013-03-01 08:00 -0500 |
| Subject | Re: Triple nested loop python (While loop insde of for loop inside of while loop) |
| From | Joel Goldstick <joel.goldstick@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2719.1362142804.2939.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
On Fri, Mar 1, 2013 at 7:00 AM, Ulrich Eckhardt <
ulrich.eckhardt@dominolaser.com> wrote:
> Am 01.03.2013 09:59, schrieb Isaac Won:
>
> try to make my triple nested loop working. My code would be:
>> c = 4
>>
> [...]
>
> while c <24:
>> c = c + 1
>>
>
> This is bad style and you shouldn't do that in python. The question that
> comes up for me is whether something else is modifying "c" in that loop,
> but I think the answer is "no". For that reason, use Python's way:
>
> for c in range(5, 25):
> ...
>
> That way it is also clear that the first value in the loop is 5, while the
> initial "c = 4" seems to suggest something different. Also, the last value
> is 24, not 23.
>
>
>
> I concur with Uli, and add the following thoughts: What is going on with
[y]? Is this really a list? So what is y1 + y1 + [y] doing?
>
> while d <335:
>> d = d + 1
>> y = fpsd[d]
>> y1 = y1 + [y]
>> m = np.mean(y1)
>> m1 = m1 + [m]
>>
>
> In your outer loop you initialize these values each pass:
dt = 900.0 #Time step (seconds)
fs = 1./dt #Sampling frequency
This should me moved out of the loop since nothing changes with dt or fs
> Apart from the wrong indention (don't mix tabs and spaces, see PEP 8!) and
> the that "d in range(336)" is better style, you don't start with an empty
> "y1", except on the first iteration of the outer loop.
>
> I'm not really sure if that answers your problem. In any case, please drop
> everything not necessary to demostrate the problem before posting. This
> makes it easier to see what is going wrong both for you and others. Also
> make sure that others can actually run the code.
>
>
> Greetings from Hamburg!
>
> Uli
>
>
>
> --
> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>
--
Joel Goldstick
http://joelgoldstick.com
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Triple nested loop python (While loop insde of for loop inside of while loop) Isaac Won <winefrog@gmail.com> - 2013-03-01 00:59 -0800
Re: Triple nested loop python (While loop insde of for loop inside of while loop) Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2013-03-01 13:00 +0100
Re: Triple nested loop python (While loop insde of for loop inside of while loop) Joel Goldstick <joel.goldstick@gmail.com> - 2013-03-01 08:00 -0500
Re: Triple nested loop python (While loop insde of for loop inside of while loop) Isaac Won <winefrog@gmail.com> - 2013-03-01 08:28 -0800
Re: Triple nested loop python (While loop insde of for loop inside of while loop) Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2013-03-04 11:08 +0100
Re: Triple nested loop python (While loop insde of for loop inside of while loop) Chris Angelico <rosuav@gmail.com> - 2013-03-02 00:41 +1100
Re: Triple nested loop python (While loop insde of for loop inside of while loop) Isaac Won <winefrog@gmail.com> - 2013-03-01 08:14 -0800
Re: Triple nested loop python (While loop insde of for loop inside of while loop) Isaac Won <winefrog@gmail.com> - 2013-03-01 08:14 -0800
Re: Triple nested loop python (While loop insde of for loop inside of while loop) Isaac Won <winefrog@gmail.com> - 2013-03-01 08:18 -0800
Re: Triple nested loop python (While loop insde of for loop inside of while loop) Isaac Won <winefrog@gmail.com> - 2013-03-01 08:18 -0800
csiph-web