> 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 think you mean:
q = [ item for item in j if item % 2]
item % 2 will return zero = false on even numbers, so
your test is true for od
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 it
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 indexe
You can also iterate over a copy of the list and change the original.
i.e.
a = range(10)
for x in a[:]:
if x % 2 == 0:
a.remove(x)
print a
And yes, I did test it this time.
Jacob
>for x in string:
>if x in chars:
>string[i] = ''
I just have a hangover from other
> >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
loo
> > 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:
>
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
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
__
Orri Ganel wrote:
Kent Johnson wrote:
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:
Kent Johnson wrote:
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:
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:
string.re
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 to
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 comman
Hello all,
> > So, how would one go about this in a non broken code way? Don't they
> have
> > something like what I'm requesting.
If not,it's a challenge you can implement yourself! Ever use QBasic?
Had a command -
a$ = inkey$(1)
Which would return a key press as a$.
Very handy for 'press a
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 mu
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
collect
> 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.l
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 astr
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 pl
Jacob S. wrote:
I don't know who's going crazy here... but I checked that straight from
the python 2.4 interpreter...
>>> a = "go on long buddy"
>>> a.lstrip('gonl')
' on long buddy'
>>> a.lstrip('gonl ')
'buddy'
>>>
Note that in the second case, I've included a space in the lstrip()
parameter.
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 lo
> 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 newbi
> 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 bette
> 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 tak
Danny Yoo wrote:
On Mon, 31 Jan 2005, Jacob S. wrote:
### Pseudocode
commandDispatchTable = {'clear' : clearCommand
'quit' : quitCommand
'remove' : removeCommand
'return' : returnCommand
'gatl'
On Mon, 31 Jan 2005, Jacob S. wrote:
> BTW, it was a few months ago, not days... but the thought still counts.
> At least you remember.
Hi Jacob,
Wait, was it really a few months ago? Let me check the archive...
http://mail.python.org/pipermail/tutor/2004-December/033728.html
You're ri
Ah, I like.
BTW, it was a few months ago, not days... but the thought still counts. At
least you remember.
I was getting stumped by the difference in comparing y
The check for seeing what the first word is made me slamp my forehead...
Thanks!
Jacob Schmidt
On Mon, 31 Jan 2005, Jacob S. wrote:
I
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
What, like
global radiusaxis, radiusaxis2
Simil
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 in
> 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 ca
I think this thing is screaming for better structure, but previous attempts
at using oop for it have failed.
I think Derintegral is okay, I'm focusing on FunctionGrapher5.py--but you
can comment on both.
(To Johan Nilsson: I haven't had time to implement Simpson's rule instead of
Reimann's sum y
31 matches
Mail list logo