The while loop will print each index of the list. In a way it checks that if
the list is empty by printing the items. As far as I know there isn't any
'True' or 'False' output from a list.
If you want to do something if mylist is empty you can check it like this:
if not mylist:
... do someth
On Mon, Oct 19, 2009 at 3:29 AM, Wayne wrote:
> Hi, I think I recall seeing this here, but I wanted to make sure I'm
> correct.
> Is the best way to test for an empty list just test for the truth value?
> I.e.
> mylist = [1,2,3]
> while mylist:
> print mylist.pop()
Whether it is the 'best' way
"Todd Matsumoto" wrote
The while loop will print each index of the list.
No, the while does nothing with list indexes, that is entirely
down to the programmer. The while loop simply repeats for
as long as its test expression evaluates to True.
As far as I know there isn't any 'True' or 'Fal
On Mon, Oct 19, 2009 at 2:26 AM, Todd Matsumoto wrote:
> The while loop will print each index of the list.
No it's printing each element of the list, not the index.
> In a way it checks that if the list is empty by printing the items. As far
> as I know there isn't any 'True' or 'False' output
Wayne wrote:
Hi, I think I recall seeing this here, but I wanted to make sure I'm
correct.
Is the best way to test for an empty list just test for the truth value?
I.e.
mylist = [1,2,3]
while mylist:
print mylist.pop()
Thanks,
Wayne
My take is simple: Use the above form if you *know*
I don't understand how the while loop efficiently tests if the list is empty.
Why would going through the entire list be a good test to simply see find out
if the list is empty or not.
Wouldn't you want to test the list itself, rather than the contents of it?
Cheers,
T
Original-Nachr
Hi,
please don't top-post.
Todd Matsumoto wrote:
> I don't understand how the while loop efficiently tests if the list is
> empty.
It doesn't. It only tests a condition. And the result of the condition is
determined by the list itself, which knows if it's empty or not.
Stefan
On Sunday, October 18, 2009, Serdar Tumgoren wrote:
> Hi everyone,
> I'm trying to create a generic logging function, and I'm able to get
> at the name of the module and class using the built-in attributes
> __module__, __class__, and __name__.
>
> But I wasn't sure how to also grab the name of th
Kent Johnson wrote:
On Sunday, October 18, 2009, Serdar Tumgoren wrote:
Hi everyone,
I'm trying to create a generic logging function, and I'm able to get
at the name of the module and class using the built-in attributes
__module__, __class__, and __name__.
But I wasn't sure how to also grab th
> Or just use the built-in logging module which lets you specify
> the containing function name as one of its formatting keywords:
>
> http://docs.python.org/library/logging.html#formatter-objects
>
Aha! I had skimmed the logging docs, but hadn't gone far enough down
to notice the %(funcName)s for
On Mon, Oct 19, 2009 at 8:40 AM, Tim Golden wrote:
> Or just use the built-in logging module which lets you specify
> the containing function name as one of its formatting keywords:
>
> http://docs.python.org/library/logging.html#formatter-objects
Sweet! And much better than rolling your own log
Wayne wrote:
Hi, I think I recall seeing this here, but I wanted to make sure I'm
correct.
Is the best way to test for an empty list just test for the truth value?
I.e.
mylist = [1,2,3]
while mylist:
print mylist.pop()
Thanks,
Wayne
My take is simple: Use the above form if you *know* th
Hi all,
I am a PHP developer that just started learning Python for a specific
application and the transition has been pretty easily assisted by google,
but I just dont see the issue with this one?
Ive got a list that created and populate in a loop that shows the correct
info when I print
2009/10/19 Katt
>
> Hello all,
>
> Just a newbie question, but when would you test for an empty list? Is it
> part of a code error detection or an error check to make sure that there is
> user input?
>
> Couldn't you just use something like:
>
> while len(mylist) > 0:
> continue program
> els
Hello,
The other day I was making a script and decided to use a list
compreehension and I found out that this code:
mylist = ['John', 'Canada', 25, 32, 'right']
a = [item.upper() for item in mylist if type(item) == type('good')]
returned this: ['JOHN', 'CANADA', 'RIGHT']
I was expecting this: ['JOH
Hi All.
The below script seems to work well enough to use but I'm wondering if I'm
doing the file edit stuff in a "kosher" manner. I was just reading the Lutz
O'Reilly "Learning" book and remembered that strings are immutable. So how was
I able to change the strings for my dotted quad? I did no
2009/10/19 Eduardo Vieira :
> mylist = ['John', 'Canada', 25, 32, 'right']
> a = [item.upper() for item in mylist if type(item) == type('good')]
Usually it is recommended to use hasattr() instead of type()
hasattr(s, 'upper')
> returned this: ['JOHN', 'CANADA', 'RIGHT']
> I was expecting this
On Mon, Oct 19, 2009 at 11:39 AM, Eduardo Vieira wrote:
> Hello,
> The other day I was making a script and decided to use a list
> compreehension and I found out that this code:
> mylist = ['John', 'Canada', 25, 32, 'right']
> a = [item.upper() for item in mylist if type(item) == type('good')]
> r
Mike Sweany wrote:
Hi all,
I am a PHP developer that just started learning Python for a specific
application and the transition has been pretty easily assisted by google,
but I just don’t see the issue with this one?
I’ve got a list that created and populate in a loop that shows the cor
"Katt" wrote
Just a newbie question, but when would you test for an empty list?
When you are processing a list such that you are deleting items as you go.
When the list is empty stop processing!
And Python helps you do that by treating an empty list as a False
boolean value so you can do
"Matt Herzog" wrote
remembered that strings are immutable.
So how was I able to change the strings for my dotted quad?
You didn't.
LASTKNOWN = '173.48.204.168'
lns = cf.readlines()
lns = "".join(lns)
lns = re.sub(LASTKNOWN, CURRENT, lns)
I assume this is the line in question?
s
"Sander Sweers" wrote
mylist = ['John', 'Canada', 25, 32, 'right']
a = [item.upper() for item in mylist if type(item) == type('good')]
Usually it is recommended to use hasattr() instead of type()
hasattr(s, 'upper')
Nope, they do completely different things
I think you might be thinkin
2009/10/19 Alan Gauld :
>> Usually it is recommended to use hasattr() instead of type()
>> hasattr(s, 'upper')
>
> Nope, they do completely different things
> I think you might be thinking of isinstance() which can be used instead of
> type(). I see you use hasattr as a means of testing for a me
On 10/19/2009 12:20 PM Alan Gauld said...
"Sander Sweers" wrote
mylist = ['John', 'Canada', 25, 32, 'right']
a = [item.upper() for item in mylist if type(item) == type('good')]
Usually it is recommended to use hasattr() instead of type()
hasattr(s, 'upper')
Nope, they do completely di
On Mon, Oct 19, 2009 at 1:58 PM, Emile van Sebille wrote:
> On 10/19/2009 12:20 PM Alan Gauld said...
>
>
>> "Sander Sweers" wrote
>>
>> mylist = ['John', 'Canada', 25, 32, 'right']
a = [item.upper() for item in mylist if type(item) == type('good')]
>>>
>>> Usually it is recommended t
On Mon, Oct 19, 2009 at 2:14 PM, vince spicer wrote:
>
>
> On Mon, Oct 19, 2009 at 1:58 PM, Emile van Sebille wrote:
>
>> On 10/19/2009 12:20 PM Alan Gauld said...
>>
>>
>>> "Sander Sweers" wrote
>>>
>>> mylist = ['John', 'Canada', 25, 32, 'right']
> a = [item.upper() for item in mylist if
On Mon, Oct 19, 2009 at 9:20 PM, Alan Gauld wrote:
>
>
> "Sander Sweers" wrote
>
> mylist = ['John', 'Canada', 25, 32, 'right']
>>> a = [item.upper() for item in mylist if type(item) == type('good')]
>>>
>>
>> Usually it is recommended to use hasattr() instead of type()
>> hasattr(s, 'upper')
On or about 2009 Oct 19, at 3:57 PM, Sander Sweers indited:
I missed that the try: did not return anything. I was thinking more of
something like this.
def upperfy(item):
try:
item.upper()
return item
except AttributeError:
return item
Thanks for correcting me!
Depe
On Mon, Oct 19, 2009 at 1:20 PM, Alan Gauld wrote:
>
> "Sander Sweers" wrote
>
>>> mylist = ['John', 'Canada', 25, 32, 'right']
>>> a = [item.upper() for item in mylist if type(item) == type('good')]
>>
>> Usually it is recommended to use hasattr() instead of type()
>> hasattr(s, 'upper')
>
> N
Is there any compelling reason to write:
>
>[item.upper() for item in my_list if isinstance(item, basestring)]
>
>rather than the following?
>
>[item.upper() for item in my_list if hasattr(item, 'upper')]What happens if
>you have an object in your list that has
an 'upper' merthod that, say, reboo
"Emile van Sebille" wrote
a = [item.upper() if type(item) == str else item for item in mylist]
should do it I think.
or even
a = [ str(item).upper() for item in mylist ]
That was my first attempt but the OP wanted his integers preserved
as integers whereas this would convert them to
"vince spicer" wrote
Lambda can save the day to keep everything on one line, and leave
variable
type the same:
mylist = ['John', 'Canada', 25, 32, 'right']
new_list = [(lambda y: y.upper() if hasattr(y, 'upper') else y)(a) for a
in
mylist ]
>> ['JACK', 'CANADA', 25, 32, 'RIGHT']
Vince
Ooops, hit send by mistake...
"vince spicer" wrote
Lambda can save the day to keep everything on one line, and leave
variable
type the same:
mylist = ['John', 'Canada', 25, 32, 'right']
new_list = [(lambda y: y.upper() if hasattr(y, 'upper') else y)(a) for a
in
mylist ]
>> ['JACK', 'CANA
On Mon, Oct 19, 2009 at 08:07:47PM +0100, Alan Gauld wrote:
>
> "Matt Herzog" wrote
>
> >remembered that strings are immutable.
> >So how was I able to change the strings for my dotted quad?
>
> You didn't.
>
> >LASTKNOWN = '173.48.204.168'
> > lns = cf.readlines()
> > lns = "".join(lns)
On Mon, Oct 19, 2009 at 07:51:06PM -0400, Matt Herzog wrote:
> On Mon, Oct 19, 2009 at 08:07:47PM +0100, Alan Gauld wrote:
> >
> > "Matt Herzog" wrote
> >
> > >remembered that strings are immutable.
> > >So how was I able to change the strings for my dotted quad?
> >
> > You didn't.
> >
> >
Hey tutors. I have a TI-84 plus, and I am making some math tools, and I
don't know the native language of the Ti-84, and was wondering, has
anyone worked with a version of Python that can run on that small of a
processor? Thanks in advance,
~Corey
___
Thanks for the reply and Tips Dave...
I think the formatting came out weird because I didnt specify plain text
when I created the email.
I'm using Google App Engine and it's internal debugger shows what I posted
earlier when the code breaks, I agree that what I am seeing from the
debugger makes
37 matches
Mail list logo