Bart Willems wrote:
> I have a feeling that there's a Python-solution that is shorter yet
> better readable, I just can't figure it out yet...
Shorter (and faster for big lists): Yes. More readable: I don't know, I
guess that depends on ones familiarity with the procedure.
import bisect
def g
> if points > 89 and points <= 100:
> return "A"
> elif points > 89 and points <= 89:
> return "B"
> elif points > 69 and points <= 79:
> return "C"
> elif points > 59 and points <= 69:
> return "D"
> else:
> return "F"
The previous poste
Thanks for help!
--
http://mail.python.org/mailman/listinfo/python-list
On Apr 14, 10:19 am, [EMAIL PROTECTED] wrote:
> Hi!
> I ran in problem with simple exercise. I'm trying to get program to
> return grade when given points but no matter what, I always get F.
>
> def grader():
> print "Insert points: "
> points = raw_input('> ')
> int(points)
>
>
On Apr 14, 5:19 pm, [EMAIL PROTECTED] wrote:
> Hi!
> I ran in problem with simple exercise. I'm trying to get program to
> return grade when given points but no matter what, I always get F.
>
> def grader():
> print "Insert points: "
> points = raw_input('> ')
> int(points)
>
>
Hi!
I ran in problem with simple exercise. I'm trying to get program to
return grade when given points but no matter what, I always get F.
def grader():
print "Insert points: "
points = raw_input('> ')
int(points)
if points > 89 and points <= 100:
return "A"
eli
Tim Henderson wrote:
> peter
(Thanks for clarifying to whom you were responding... I saw the other
post but wouldn't have responded since it didn't seem to be in response
to one of mine. :-) )
> would not the more correct way to do this be short circuit
> evaluation. somthing along lines of
>
peter
would not the more correct way to do this be short circuit
evaluation. somthing along lines of
if (len(item) > 0) and (item[0] == '-'): pass
seems to be the more correct approach. rather than relying on slicing
to return an empty string. For instance suppose you wanted to test to
see if th
of course the more correct way is most likely the use of short circuit
evaluation. so somthing along lines of
if (len(item) > 0) and (item[0] == '-'): pass
would probably be the correct approach.
--
http://mail.python.org/mailman/listinfo/python-list
Fredrik Lundh wrote:
> Peter Hansen wrote:
>>Actually, it's not so much baroque as it is safe... item[0] will fail if
>>the string is empty, while item[0:1] will return '' in that case.
>>
>>Of course, as you point out, .startswith() is the better approach anyway.
>
> $ timeit -s "s = 'abc'" "s[:1
I think no matter what language you programs it, it is hard to
understand. Can you break it up into sub-problems first ? Like first
parsing the inventory file into a python dict, then also the fields
from web to another dict ?
Chris wrote:
> Hi,
>
> I'm new to python, and I'm trying to write a sma
Peter Hansen wrote:
> Actually, it's not so much baroque as it is safe... item[0] will fail if
> the string is empty, while item[0:1] will return '' in that case.
>
> Of course, as you point out, .startswith() is the better approach anyway.
$ timeit -s "s = 'abc'" "s[:1] == 'a'"
100 loops, be
Tom Anderson <[EMAIL PROTECTED]> wrote:
...
> But, more importantly, egad! What's the thinking behind having slicing
> behave like that? Anyone got any ideas? What's the use case, as seems to
> be the fashionable way of putting it these days? :)
Slicing has always been "soft" (it's OK to specif
Tom Anderson wrote:
> On Sat, 26 Nov 2005, Peter Hansen wrote:
>>Tom Anderson wrote:
>>>On Sat, 26 Nov 2005, Chris wrote:
if item[0:1]=="-":
>>>
>>>item[0:1] seems a rather baroque way of writing item[0]! I'd actually
>>>suggest writing this line like this:
>>
>>Actually, it's not so much ba
On Sat, 26 Nov 2005, Peter Hansen wrote:
> Tom Anderson wrote:
>> On Sat, 26 Nov 2005, Chris wrote:
>>
>>> if item[0:1]=="-":
>>
>> item[0:1] seems a rather baroque way of writing item[0]! I'd actually
>> suggest writing this line like this:
>
> Actually, it's not so much baroque as it is saf
Tom Anderson wrote:
> On Sat, 26 Nov 2005, Chris wrote:
>
>> if item[0:1]=="-":
>
> item[0:1] seems a rather baroque way of writing item[0]! I'd actually
> suggest writing this line like this:
Actually, it's not so much baroque as it is safe... item[0] will fail if
the string is empty, while
Chris, as well as addressing what i think is causing your problem, i'm
going to point out some bits of your code that i think could be polished a
little. It's intended in a spirit of constructive criticism, so i hope you
don't mind!
On Sat, 26 Nov 2005, Chris wrote:
>if item[0:1]=="-":
it
Hi,
I'm new to python, and I'm trying to write a small python script for a
webpage. The script opens up a file called inventory, reads the
contents, and checks the contents against the data from the form in my
webpage. Now I have to do some slicing to get the name of the form
elements (in this c
18 matches
Mail list logo