for x in string:
if x in chars:
string[i] = ''
I just have a hangover from other languages, but I really wanted to
know
how Python handles iteration over a variable which is being changed
within the loop itself. Is the for condition evaluated in every
loop?
Its bad
Alan said -
Its bad practice to delete a member in the collection being iterated
but Python copes OK if you just change the current item.
Yeah, that's very bad. Makes for all sorts of subtle errors. I usually
do the iteration as a for i in range(len(someList) type thing, and
collect the indexes
Although, (and this will be rough) a list comprehension would be
probably do the same thing
j=[1, 2,3,4, 5,6,7,8]
q = [if not item % 2 for item in j]
I really think I've got that 'if not item % 2' wrong, as I can't test
it, but I'd be hoping for
print q
[1, 3, 5, 7]
Backwards. ;-)
q = [item for
I don't know who's going crazy here... but I checked that straight
from the
python 2.4 interpreter...
Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)]
on win32
Type help, copyright, credits or license for more
information.
a = go on long buddy
a.lstrip(gonl)
' on long
On Tue, 1 Feb 2005, Jacob S. wrote:
Also why shouldn't string methods include stuff like lstrip which do
precisely what I request?
Hi Jacob,
I think the confusion here is that, in Python, strings can be considered a
concrete single thing, but they can also be considered an ordered
Jacob,
Writing library code is a difficult and unrewarding task
- I've been there so I sympathise, however...
So, how would one go about this in a non broken code way? Don't they
have
something like what I'm requesting.
Its not broken, its just different to what you want.
What you want is
I would at least introduce some functions. For example each case of your command handling loop could
be broken out into a separate function. If there is a lot of shared state between the functions then
make them all class methods and put the shared state in the class. Maybe all the drawing
Interesting topic.
Jacob,
Writing library code is a difficult and unrewarding task
- I've been there so I sympathise, however...
I wouldn't say that...
So, how would one go about this in a non broken code way? Don't they
have
something like what I'm requesting.
Its not broken, its just different
Jacob S. wrote:
Try writing the code to do what lstrip actually does
- its much harder. So the library includes the more
difficult function and lets you code the easy ones.
def lstrip(string,chars=' ')
string = list(string)
t = 0
for x in string:
if x in chars:
for x in string:
if x in chars:
string[i] = ''
I just have a hangover from other languages, but I really wanted to know
how Python handles iteration over a variable which is being changed
within the loop itself. Is the for condition evaluated in every loop?
- Sandip
Sandip Bhattacharya wrote:
for x in string:
if x in chars:
string[i] = ''
I just have a hangover from other languages, but I really wanted to
know how Python handles iteration over a variable which is being
changed within the loop itself. Is the for condition evaluated in
Danny Yoo wrote:
On Mon, 31 Jan 2005, Jacob S. wrote:
### Pseudocode
commandDispatchTable = {'clear' : clearCommand
'quit' : quitCommand
'remove' : removeCommand
'return' : returnCommand
'gatl'
http://www.cs.bell-labs.com/cm/cs/pearls/
That link seems to be dead. Pity. My whole programming experience is
comprised of Ah-Ha's followed by Um's...
--
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to
What, like
global radiusaxis, radiusaxis2
exactly.
And since there is no input parameter and no return statement
and you only call start() once...
Not true. If y == 'clear', then start is called to redraw the
window.
Very important part.
OK, I missed that, but its still better to hide
ever get the chance, you may want to take a look at a book called
Programming Pearls:
http://www.cs.bell-labs.com/cm/cs/pearls/
I'll second that. Personally I try to read both books
(I have the original 2 volume version!) every couple of years
- they are that valuable. Most newbie
So, how would one go about this in a non broken code way? Don't they have
something like what I'm requesting.
It seems to me that a few things are flawed in the standard distribution.
Little things like the overlooking of adding a method or function to decimal
for returning an instance with x
Jacob S. wrote:
So, how would one go about this in a non broken code way? Don't they
have something like what I'm requesting.
No, but it's pretty easy to do:
def exact_lstrip(astring, stripstring):
if astring.startswith(stripstring):
astring = astring[len(stripstring):]
return
def start():
lots of lines...
global xaxis
global yaxis
Its traditional to put global statements at the top of the function.
Also you only need one line to list all of the global variables
global radiusaxis
global radiusaxis2
Similarly here., and again you can
On Mon, 31 Jan 2005, Jacob S. wrote:
I think this thing is screaming for better structure, but previous attempts
at using oop for it have failed.
Hi Jacob,
Ok, I see one big refactoring that should help things quite a bit.
There's a large case-analysis off if/elif/elif statements that
19 matches
Mail list logo