Re: how to exit from a nested loop in python

2019-02-09 Thread DL Neil
On 8/02/19 7:45 PM, Kaka wrote: for i in range(len(A.hp)): for j in range(len(run_parameters.bits_Mod)): req_slots[j] = math.ceil((A.T[i]) for g in Temp[i]["Available_ranges"][j]: for s in range(g[0], g[-1]): if (s+req_slots[j]-1) <= g[-1]

Re: how to exit from a nested loop in python

2019-02-08 Thread Rurpy via Python-list
On Thursday, February 7, 2019 at 11:45:23 PM UTC-7, Kaka wrote: > for i in range(len(A.hp)): > > for j in range(len(run_parameters.bits_Mod)): > req_slots[j] = math.ceil((A.T[i]) > > for g in Temp[i]["Available_ranges"][j]: > for s in range(g[0], g[-1]): >

Re: how to exit from a nested loop in python

2019-02-08 Thread Peter Otten
Kaka wrote: > for i in range(len(A.hp)): > > for j in range(len(run_parameters.bits_Mod)): > req_slots[j] = math.ceil((A.T[i]) > > for g in Temp[i]["Available_ranges"][j]: > for s in range(g[0], g[-1]): > if (s+req_slots[j]-1) <= g[-1]: >

how to exit from a nested loop in python

2019-02-07 Thread Kaka
for i in range(len(A.hp)): for j in range(len(run_parameters.bits_Mod)): req_slots[j] = math.ceil((A.T[i]) for g in Temp[i]["Available_ranges"][j]: for s in range(g[0], g[-1]): if (s+req_slots[j]-1) <= g[-1]: if (Temp[i]['cost'][

Re: for loop in python

2016-04-28 Thread BartC
On 28/04/2016 10:34, g.v.aar...@skct.edu.in wrote: start_list = [5, 3, 1, 2, 4] square_list = [] # Your code here! for square_list in start_list: x = pow(start_list, 2) square_list.append(x) square_list.sort() print square_list TypeError: unsupported operand type(s) for ** or pow(): 'l

Re: for loop in python

2016-04-28 Thread Peter Otten
g.v.aar...@skct.edu.in wrote: > start_list = [5, 3, 1, 2, 4] > square_list = [] > > # Your code here! > for square_list in start_list: You are iterating over start_list, that's OK. But you are assigning the current value to square_list, a variable name that you already use for the list where y

Re: for loop in python

2016-04-28 Thread Steven D'Aprano
On Thu, 28 Apr 2016 07:34 pm, g.v.aar...@skct.edu.in wrote: > start_list = [5, 3, 1, 2, 4] > square_list = [] Here you set square_list to a list. > # Your code here! > for square_list in start_list: .^ Here you set square_list to each item of the start_list. So the first time ar

for loop in python

2016-04-28 Thread g . v . aarthi
start_list = [5, 3, 1, 2, 4] square_list = [] # Your code here! for square_list in start_list: x = pow(start_list, 2) square_list.append(x) square_list.sort() print square_list TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'int' Please provide me the solution for the

Re: Need help about for loop in python 3.2

2011-06-23 Thread Ben Finney
kkiranmca writes: > Hi i am new for this version and could please help me . Welcome! Don't ask whether you can ask. Just ask. http://catb.org/~esr/faqs/smart-questions.html> -- \ “I put contact lenses in my dog's eyes. They had little | `\ pictures of cats on them. Then I to

Re: Need help about for loop in python 3.2

2011-06-23 Thread Chris Rebert
On Wed, Jun 22, 2011 at 11:50 PM, kkiranmca wrote: > Hi i am new for this version and could please help me . You didn't pose an actual question... Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list

Need help about for loop in python 3.2

2011-06-22 Thread kkiranmca
Hi i am new for this version and could please help me . -- http://mail.python.org/mailman/listinfo/python-list

Re: How to write a simple shell loop in python?

2009-01-23 Thread Dietrich Bollmann
; Dietrich Bollmann wrote: > > Hi, > > > > I am trying to write a simple shell loop in Python. > > > > My simple approach works fine - but the first output line after entering > > something is always indented by one blank. > > > > Is there any logic expla

Re: How to write a simple shell loop in python?

2009-01-21 Thread Scott David Daniels
Dietrich Bollmann wrote: I am trying to write a simple shell loop in Python. My simple approach works fine - but the first output line after entering something is always indented by one blank. Is there any logic explanation for this? Yes How can I get rid of the blank? By not asking for

Re: How to write a simple shell loop in python?

2009-01-21 Thread Steve Holden
Dietrich Bollmann wrote: > Hi, > > I am trying to write a simple shell loop in Python. > > My simple approach works fine - but the first output line after entering > something is always indented by one blank. > > Is there any logic explanation for this? > How

Re: How to write a simple shell loop in python?

2009-01-20 Thread Ben Finney
Dietrich Bollmann writes: > I am trying to write a simple shell loop in Python. You should investigate the ‘cmd’ module in the standard library http://docs.python.org/library/cmd.html>. > My simple approach works fine - but the first output line after > entering something is always

Re: How to write a simple shell loop in python?

2009-01-20 Thread James Mills
On Wed, Jan 21, 2009 at 3:12 PM, Saul Spatz wrote: > Strange. I don't have an explanation, but experiment shows that if you > change print "$ ", to print "$ " (that is, leave out the comma) then the > leading blank is not printed. This behavior doesn't depend on the "print > input" statement's b

Re: How to write a simple shell loop in python?

2009-01-20 Thread Saul Spatz
Dietrich Bollmann wrote: Hi, I am trying to write a simple shell loop in Python. My simple approach works fine - but the first output line after entering something is always indented by one blank. Is there any logic explanation for this? How can I get rid of the blank? Is there a smarter

How to write a simple shell loop in python?

2009-01-20 Thread Dietrich Bollmann
Hi, I am trying to write a simple shell loop in Python. My simple approach works fine - but the first output line after entering something is always indented by one blank. Is there any logic explanation for this? How can I get rid of the blank? Is there a smarter way to write a simple shell

Re: How to make a reverse for loop in python?

2008-09-21 Thread Alex Snast
On Sep 21, 3:47 am, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Sat, 20 Sep 2008 16:27:41 -0700, Alex Snast wrote: > > Another quick question please, is the List data structure just a dynamic > > array? If so how can you use static size array, linked list, AVL trees > > etcet

Re: How to make a reverse for loop in python?

2008-09-20 Thread Steven D'Aprano
On Sun, 21 Sep 2008 01:56:59 +0200, Christian Heimes wrote: > Just *don't* try to abuse lists by creating fancy stuff e.g. linked > lists. The memory overhead is going to kill your app. I agree with your advice not to abuse lists, but not for the reason you give. The memory overhead of a linked

Re: How to make a reverse for loop in python?

2008-09-20 Thread Steven D'Aprano
On Sat, 20 Sep 2008 16:27:41 -0700, Alex Snast wrote: > Another quick question please, is the List data structure just a dynamic > array? If so how can you use static size array, linked list, AVL trees > etcetera. Before I answer your question, I should say that you can go a LONG way with just t

Re: How to make a reverse for loop in python?

2008-09-20 Thread bearophileHUGS
Christian Heimes: > Unless you have specific needs for highly specialized data types, use lists. There's also the collections.deque for other related purposes. (I suggest people willing to look at some nice C code to read the sources of deque, Hettinger has created some refined code, very readabl

Re: How to make a reverse for loop in python?

2008-09-20 Thread Steven D'Aprano
On Sat, 20 Sep 2008 16:22:31 -0700, Alex Snast wrote: > That's a lot of responses guys. Thanks a lot i think i got it. Another > question, are there any pointers in python (or iterators) for when i use > a data structure that doesn't support random access? That surely depends on the data structu

Re: How to make a reverse for loop in python?

2008-09-20 Thread Gabriel Genellina
En Sat, 20 Sep 2008 20:27:41 -0300, Alex Snast <[EMAIL PROTECTED]> escribió: Another quick question please, is the List data structure just a dynamic array? If so how can you use static size array, linked list, AVL trees etcetera. Yes, lists are implemented as dynamic arrays (but you shouldn't

Re: How to make a reverse for loop in python?

2008-09-20 Thread Christian Heimes
Alex Snast wrote: Another quick question please, is the List data structure just a dynamic array? If so how can you use static size array, linked list, AVL trees etcetera. You should treat Python lists as an opaque item. You shouldn't concern yourself with the implementation details. Python li

Re: How to make a reverse for loop in python?

2008-09-20 Thread Alex Snast
On Sep 20, 8:13 pm, [EMAIL PROTECTED] wrote: > Duncan Booth: > > > > e.g. the python equivalent to the c++ loop > > > for (i = 10; i >= 0; --i) > > > The exact equivalent would be: > >         for i in range(10, -1, -1): print i > > I'd use xrange there. Anyway, I have always felt that Python synta

Re: How to make a reverse for loop in python?

2008-09-20 Thread Alex Snast
On Sep 20, 8:13 pm, [EMAIL PROTECTED] wrote: > Duncan Booth: > > > > e.g. the python equivalent to the c++ loop > > > for (i = 10; i >= 0; --i) > > > The exact equivalent would be: > >         for i in range(10, -1, -1): print i > > I'd use xrange there. Anyway, I have always felt that Python synta

Re: How to make a reverse for loop in python?

2008-09-20 Thread bearophileHUGS
Duncan Booth: > > e.g. the python equivalent to the c++ loop > > for (i = 10; i >= 0; --i) > > The exact equivalent would be: > for i in range(10, -1, -1): print i I'd use xrange there. Anyway, I have always felt that Python syntax not easy to understand at first sight, expecially when you

Re: How to make a reverse for loop in python?

2008-09-20 Thread Peter Otten
Gary Herron wrote: > Or you can create a new reversed (copy of the original) list and iterate > through it > > for item in reversed(L): >   print item It's not a copy, it's a view: >>> items = [1,2,3] >>> r = reversed(items) >>> items[:] = "abc" >>> for item in r: print item ... c b a Peter -

Re: How to make a reverse for loop in python?

2008-09-20 Thread Fredrik Lundh
Fredrik Lundh wrote: e.g. the python equivalent to the c++ loop for (i = 10; i >= 0; --i) use range with a negative step: for i in range(10-1, -1, -1): ... or just reverse the range: for i in reversed(range(10)): ... (and to include the 10 in the range, add one to

Re: How to make a reverse for loop in python?

2008-09-20 Thread Gary Herron
Alex Snast wrote: Hello I'm new to python and i can't figure out how to write a reverse for loop in python e.g. the python equivalent to the c++ loop for (i = 10; i >= 0; --i) -- http://mail.python.org/mailman/listinfo/python-list What are you trying to loop through?

Re: How to make a reverse for loop in python?

2008-09-20 Thread Fredrik Lundh
Alex Snast wrote: I'm new to python and i can't figure out how to write a reverse for loop in python e.g. the python equivalent to the c++ loop for (i = 10; i >= 0; --i) use range with a negative step: for i in range(10-1, -1, -1): ... or just reverse the range:

Re: How to make a reverse for loop in python?

2008-09-20 Thread Simon Brunning
2008/9/20 Alex Snast <[EMAIL PROTECTED]>: > I'm new to python and i can't figure out how to write a reverse for > loop in python > > e.g. the python equivalent to the c++ loop > > for (i = 10; i >= 0; --i) for i in range(10, 0, -1): print i -- Cheer

Re: How to make a reverse for loop in python?

2008-09-20 Thread Duncan Booth
Alex Snast <[EMAIL PROTECTED]> wrote: > Hello > > I'm new to python and i can't figure out how to write a reverse for > loop in python > > e.g. the python equivalent to the c++ loop > > for (i = 10; i >= 0; --i) > The exact equivalent would be

Re: How to make a reverse for loop in python?

2008-09-20 Thread Mensanator
On Sep 20, 11:16�am, Alex Snast <[EMAIL PROTECTED]> wrote: > Hello > > I'm new to python and i can't figure out how to write a reverse for > loop in python > > e.g. the python equivalent to the c++ loop > > for (i = 10; i >= 0; --i) >>> for i i

Re: How to make a reverse for loop in python?

2008-09-20 Thread Thoma
Alex Snast a écrit : Hello I'm new to python and i can't figure out how to write a reverse for loop in python e.g. the python equivalent to the c++ loop for (i = 10; i >= 0; --i) for (i = 0; i < 10; i--) -> for i in range(10): for (i = 10; i >= 0; --i) -> for i i

How to make a reverse for loop in python?

2008-09-20 Thread Alex Snast
Hello I'm new to python and i can't figure out how to write a reverse for loop in python e.g. the python equivalent to the c++ loop for (i = 10; i >= 0; --i) -- http://mail.python.org/mailman/listinfo/python-list

Re: loop in python

2005-08-25 Thread travlr
I gotta say that as number cruncher, iteration in python is my biggest nightmare. I do what is possible with numpy, but element by element processing is a hassle. My programming experience is still pretty fresh at a year, so "exotics" as such are not in play yet. I also wish python looping/iterativ

Re: loop in python

2005-08-25 Thread James
>> I don't want to offend you or anything, but doesn't the second sentence mean >> that someone DID do a speed comparison? I did provide Language Shootout link in the next paragraph of the post you referred to along with an obligatory caution about interpreting benchmarks. The Language Shootout i

Re: loop in python

2005-08-25 Thread Sybren Stuvel
Peter Hansen enlightened us with: > Yes, and has shown that they are in the same ballpark, and therefore > one does not _need_ to compare speed any more. Ok. I'd worded it as "there have been tests already, so there is no need to do your own", instead of "one does not test". Sybren -- The proble

Re: loop in python

2005-08-25 Thread Peter Hansen
Sybren Stuvel wrote: > James enlightened us with: > >>One does not compare speed when they use Perl/Python/Ruby/Tcl. They >>are all more or less in the same performance ball park. > > > I don't want to offend you or anything, but doesn't the second > sentence mean that someone DID do a speed com

Re: loop in python

2005-08-25 Thread Sybren Stuvel
James enlightened us with: > One does not compare speed when they use Perl/Python/Ruby/Tcl. They > are all more or less in the same performance ball park. I don't want to offend you or anything, but doesn't the second sentence mean that someone DID do a speed comparison? Sybren -- The problem wi

Re: loop in python

2005-08-25 Thread James
I am going to be a bit blunt. Don't get offended. >> Also the first thing any newbie to python asks me is abt "raw speed in >> comparison with similar languages like perl" when i advocate python to perl. Judging by your other posts, you are a newbie yourself. You are not really in a position to

Re: loop in python

2005-08-25 Thread km
Hi all, > What you are "comparing" is either IO times (the "print loop" program), > where Perl beats C - which means that Perl's IO have been written at a > very low level instead of relying on the stdlib's IO - i'd like to know what aspects are really coded in very low level for python ? rega

Re: loop in python

2005-08-24 Thread bruno modulix
Terry Hancock wrote: > On Tuesday 23 August 2005 05:35 am, bruno modulix wrote: > (snip) >> >>If you hope to be taken seriously, please abandon the sms-talk style here. >> > > > I think it's reasonably clear that neither poster hoped "to be taken > seriously". :-D > Err... I guess that "to be

Re: loop in python

2005-08-23 Thread Terry Hancock
On Tuesday 23 August 2005 05:35 am, bruno modulix wrote: > km wrote: > >>If you want a fast language, try Holden. I've just invented it. > >>Unfortunately it gets the answer to every problem wrong unless the > >>answer is 42, but boy it runs quickly. The code for the whole > >>interpreter (it's

Re: loop in python

2005-08-23 Thread Fredrik Lundh
Steve Holden wrote: > If you want a fast language, try Holden. I've just invented it. > Unfortunately it gets the answer to every problem wrong unless the > answer is 42, but boy it runs quickly. The code for the whole > interpreter (it's written in Python) follows: > > print 42 > > Why are you lo

Re: loop in python

2005-08-23 Thread bruno modulix
km wrote: >>If you want a fast language, try Holden. I've just invented it. >>Unfortunately it gets the answer to every problem wrong unless the >>answer is 42, but boy it runs quickly. The code for the whole >>interpreter (it's written in Python) follows: > > >>print 42 > > > great ! u can

Re: loop in python

2005-08-23 Thread bruno modulix
Steve Holden wrote: (snip) > If you want a fast language, try Holden. I've just invented it. > Unfortunately it gets the answer to every problem wrong unless the > answer is 42, but boy it runs quickly. The code for the whole > interpreter (it's written in Python) follows: > > print 42 > keyboar

Re: loop in python

2005-08-23 Thread bruno modulix
Terry Reedy wrote: > "Benjamin Niemann" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > (snip) >>In that case, you are interested in IO performance. The time spent >>handling >>the loop is not significant compared to the time spent executing the >>'print' statement - which is a v

Re: loop in python

2005-08-23 Thread rafi
km wrote: >>that this obsession reveals a certain inexperience. > > its neither obsession nor inexperience ... its just the requirement. > i think less buggy code is not the main concern for all. Argh (choking) Then you are definitely a dangerous person! If your program is fast to give a fal

Re: loop in python

2005-08-23 Thread Randy Bush
computers are cheap. i am expensive. give me clear and maintainable code every time. randy -- http://mail.python.org/mailman/listinfo/python-list

Re: loop in python

2005-08-23 Thread Peter Otten
km wrote: > the first thing any newbie to python asks me is abt "raw speed in > comparison with similar languages like perl" when i advocate python to > perl. In that case it is easy enough to follow the common industry practice and tweak your test cases until your favourite product comes out fas

Re: loop in python

2005-08-23 Thread km
> If you want a fast language, try Holden. I've just invented it. > Unfortunately it gets the answer to every problem wrong unless the > answer is 42, but boy it runs quickly. The code for the whole > interpreter (it's written in Python) follows: > print 42 great ! u can use it for ur own proj

Re: loop in python

2005-08-22 Thread Gregory Bond
km wrote: > Is python runtime slow at all aspects when compared to perl ? And in addition to all that everyone else has said most of this is startup time. The python interpreter is a fair bit slower to start up (i.e. does much more at startup time) than the perl one: > lenford$ time pyth

Re: loop in python

2005-08-22 Thread Terry Reedy
"Benjamin Niemann" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > km wrote: > >> Hi all, >> >>> thing. If *all* your loops are going to do is print stuff, then you're >>> doing the right thing with the version that "emits values". >> >> ya most of the loops print values. > > In th

Re: loop in python

2005-08-22 Thread Terry Reedy
"km" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I agree that python emphasizes on readability which i didnt see in many > of the languages, but when the application concern is speed, does it > mean that python is not yet ready? even most of the googling abt python Funny you sh

Re: loop in python

2005-08-22 Thread Benjamin Niemann
km wrote: > Hi all, > >> thing. If *all* your loops are going to do is print stuff, then you're >> doing the right thing with the version that "emits values". > > ya most of the loops print values. In that case, you are interested in IO performance. The time spent handling the loop is not sign

Re: loop in python

2005-08-22 Thread rafi
km wrote: > Also the first thing any newbie to python asks me is abt "raw speed > in comparison with similar languages like perl" when i advocate > python to perl. Always the same chorus... Just tell the newbies that speed is not on their top list. If most of the world's computer programs wh

Re: loop in python

2005-08-22 Thread Peter Hansen
km wrote: >>thing. If *all* your loops are going to do is print stuff, then you're >>doing the right thing with the version that "emits values". > > ya most of the loops print values. No, you missed my point. I said if *all* the loops are going to do is print stuff. In other words, no other

Re: loop in python

2005-08-22 Thread Bruno Desthuilliers
km a écrit : > Hi all, > > ya i am sorry i tried with an empty loop first and then one which emits a > value as the snippet. I have tested it on my machine and now ... > > 1) perl (v 5.8) does the job in 0.005 seconds > 2) but python (v 2.4.1) is horribly slow its 0.61 seconds. > and using ran

Re: loop in python

2005-08-22 Thread Bill Mill
> If you want a fast language, try Holden. I've just invented it. > Unfortunately it gets the answer to every problem wrong unless the > answer is 42, but boy it runs quickly. +1 QOTW (sometimes the zen master has to whack the student on the head) Peace Bill Mill bill.mill at gmail.com -- http:

Re: loop in python

2005-08-22 Thread Steve Holden
km wrote: > Hi all, > > Why is it that the implementation of empty loop so slow in python when > compared to perl ? > > #i did this in python (v 1.5) > for x in xrange(1000): > print x > # this took 0.017 seconds > -- > #similar code in perl (v 5.6): > for $x (0..1

Re: loop in python

2005-08-22 Thread Bill Mill
They come out even in the computer language shootout: http://shootout.alioth.debian.org/benchmark.php?test=all&lang=python&sort=fullcpu (tied 8-8 in execution time, although perl wins 4-12 on memory consumption) Peace Bill Mill On 8/23/05, km <[EMAIL PROTECTED]> wrote: > Hi all, > > > thing.

Re: loop in python

2005-08-22 Thread km
Hi all, > thing. If *all* your loops are going to do is print stuff, then you're > doing the right thing with the version that "emits values". ya most of the loops print values. > know this). Since you haven't got any working code, it's not possible > that you *need* whatever negligible spee

Re: loop in python

2005-08-22 Thread Terry Reedy
"km" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > ya i am sorry i tried with an empty loop first and then one which emits > a value as the snippet. I have tested it on my machine and now ... > > 1) perl (v 5.8) does the job in 0.005 seconds > 2) but python (v 2.4.1) is horribly

Re: loop in python

2005-08-22 Thread Peter Hansen
km wrote: > ya i am sorry i tried with an empty loop first and then one which > emits a value as the snippet. I have tested it on my machine > and now ... > > what more do i need to accept python is slow when it comes to > loops concept ? You've sort of missed some of the points being made,

Re: loop in python

2005-08-22 Thread km
Hi all, ya i am sorry i tried with an empty loop first and then one which emits a value as the snippet. I have tested it on my machine and now ... 1) perl (v 5.8) does the job in 0.005 seconds 2) but python (v 2.4.1) is horribly slow its 0.61 seconds. and using range() instead of xrange() in p

Re: loop in python

2005-08-22 Thread D H
km wrote: > Hi all, > > Why is it that the implementation of empty loop so slow in python when > compared to perl ? > > #i did this in python (v 1.5) > for x in xrange(1000): > print x > # this took 0.017 seconds > -- > #similar code in perl (v 5.6): > for $x (0..1

Re: loop in python

2005-08-22 Thread Daniel Dittmar
km wrote: > Why is it that the implementation of empty loop so slow in python when > compared to perl ? [...] > Is python runtime slow at all aspects when compared to perl ? No > I really wonder what makes python slower than perl ? It could be that the Perl compiler recognizes such a for loo

Re: loop in python

2005-08-22 Thread bruno modulix
km wrote: > Hi all, > > Why is it that the implementation of empty loop so slow in python when > compared to perl ? > > #i did this in python (v 1.5) Python 1.5.2 was released in april 1999. Current Python version is 2.4.1. Please consider upgrading - unless of course you just want to troll..

Re: loop in python

2005-08-22 Thread Rick Wotnaz
km <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > Hi all, > > Why is it that the implementation of empty loop so slow in > python when compared to perl ? > > #i did this in python (v 1.5) > for x in xrange(1000): > print x > # this took 0.017 seconds > -- >

loop in python

2005-08-22 Thread km
Hi all, Why is it that the implementation of empty loop so slow in python when compared to perl ? #i did this in python (v 1.5) for x in xrange(1000): print x # this took 0.017 seconds -- #similar code in perl (v 5.6): for $x (0..1000) { print $x; } # this took 0.0