Le Wed, 13 May 2009 23:12:29 +0530,
Ataulla S H s'exprima ainsi:
> >>> k = [each for each in l if type(each) == type(int())]
You can write "int" (is a type since py 2.2, I guess).
assert int==type(int()) # ok
Denis
--
la vita e estrany
___
>>> l = [4, 6, 'word','a', 3, 9]
>>> l.sort()
>>> l
[3, 4, 6, 9, 'a', 'word']
>>> k = [each for each in l if type(each) == type(int())]
>>> k
[3, 4, 6, 9]
>>> kex = [each for each in l if type(each) != type(int())]
>>> kex
['a', 'word']
>>> kex+k
['a', 'word', 3, 4, 6, 9]
On Wed, May 13, 2009 at
"vince spicer" wrote
def compare(x,y):
try:
return cmp(int(x), int(y))
except:
pass
try:
int(x)
except:
return -1
try:
int(y)
except:
return 1
return 0
Or
def compare(x,y):
if type(x) == str: return -1
if type(y) == s
"Jacob Mansfield" wrote
hi everyone, I'm a bit new here but i was wondering if someone could
check
some of my code, it's not doing quite what it's meant to.
That's not very specific. What is it meant to do?
What does it actually do? Do you get any error messages?
If so post them in the emai
you can pass sort a custom compare function
Simple ex:
def compare(x,y):
try:
return cmp(int(x), int(y))
except:
pass
try:
int(x)
except:
return -1
try:
int(y)
except:
return 1
return 0
x = [4, 6, 'word', 3, 9]
x.sort(
On 5/13/2009 9:25 AM Timo said...
Hello,
I don't think this should be difficult, so maybe I look over it. But I
can't seem to find the solution.
I have a list with one word and a couple of numbers.
If this is always the case you can use the sort method of lists, then
relocate the last entr
Hello,
I don't think this should be difficult, so maybe I look over it. But I
can't seem to find the solution.
I have a list with one word and a couple of numbers. Now I want the word
to be kept in the first location and the numbers to be sorted.
So this:
[4, 6, 'word', 3, 9]
should be:
[
Le Wed, 13 May 2009 08:40:25 -0700,
Emile van Sebille s'exprima ainsi:
> On 5/13/2009 8:32 AM spir said...
> > Hello,
> >
> > I wanted to subclass the type Window of pyGTK for main app windows (for
> > the obvious reason that they always contain the same init and end code)
> > and run into an un
On 5/13/2009 8:32 AM spir said...
Hello,
I wanted to subclass the type Window of pyGTK for main app windows (for the
obvious reason that they always contain the same init and end code) and run
into an unexpected problem:
=
import pygtk
pygtk.require('2.0')
import gt
Hello,
I wanted to subclass the type Window of pyGTK for main app windows (for the
obvious reason that they always contain the same init and end code) and run
into an unexpected problem:
=
import pygtk
pygtk.require('2.0')
import gtk
# debug output
print gtk
print gtk
Jacob Mansfield wrote:
hi everyone, I'm a bit new here but i was wondering if someone could
check some of my code, it's not doing quite what it's meant to. the
problem is when you start the application again and enter the
databox.txt to load from
thanks
Databox_2_0.py:
import sys, os
pyga
"Jabin Jezreel" wrote
What is the idiomatic way to write the right side of
(a, b) = (l[0:2], l[2:])
?
(not worried about the parens, just the splitting of the sequence)
I think you have it.
I'm not aware of any better way.
--
Alan Gauld
Author of the Learn to Program web site
http://www
hi everyone, I'm a bit new here but i was wondering if someone could check
some of my code, it's not doing quite what it's meant to. the problem is
when you start the application again and enter the databox.txt to load from
thanks
Databox_2_0.py:
import sys, os
pygame.init()
def load(filename):
"Sampath Girish" wrote
Ok Now i have one more target to reach. I need to add 1st and 3rd
fields
in both the rows and place it in fourth column. Can u give me any
example?
Can you explain what you mean?
You mentioned earlier a 3x3 matrix of entry fields.
So you already have a 1st field a
Jabin Jezreel wrote:
What is the idiomatic way to write the right side of
(a, b) = (l[0:2], l[2:])
?
(not worried about the parens, just the splitting of the sequence)
___
Tu
Jabin Jezreel wrote:
What is the idiomatic way to write the right side of
(a, b) = (l[0:2], l[2:])
?
(not worried about the parens, just the splitting of the sequence)
that way is fine. Although usually it don't use parens and 0 is omitted...
a, b = l[:2], l[2:]
In python, direct index a
On Wed, May 13, 2009 at 3:58 AM, Alan Gauld wrote:
> or for platform independance:
>
> os.sep.join([src,fnames])
or os.path.join(src, fnames)
Kent
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
Ok Now i have one more target to reach. I need to add 1st and 3rd fields
in both the rows and place it in fourth column. Can u give me any example?
On Tue, May 12, 2009 at 7:51 PM, Kent Johnson wrote:
> On Tue, May 12, 2009 at 9:48 AM, Sampath Girish
> wrote:
> > Thank you Mr Kent for givin
What is the idiomatic way to write the right side of
(a, b) = (l[0:2], l[2:])
?
(not worried about the parens, just the splitting of the sequence)
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
On Wed, May 13, 2009 at 10:00 AM, Alan Gauld wrote:
>
> I may be coming across a bit strong on this one but it is such a
> fundamentally important feature of OOP that I feel on a list like tutor
> it is important to make it clear that this is not only correct behaviour
> but is very common in prac
On Wed, May 13, 2009 at 9:44 AM, spir wrote:
>
>
> Then someone stated that, except for __init__, this should be considered
> wrong. You and Kent disagreed (and indeed I do too).
Yup, that was me. I was incorrect, and am now searching around for writings
on proper OOP design with a python slant
"spir" wrote
But calling the method of a superclass from the same method is very,
very common.
Yep, for sure; and I was not discussing this actually.
(1) In fact, the whole exchange started when the OP asked how to
call 2 different methods on the same object, one beeing defined
on on its ow
Le Tue, 12 May 2009 23:23:02 +0100,
"Alan Gauld" s'exprima ainsi:
> But calling the method of a superclass from the same method is very,
> very common.
[...]
Yep, for sure; and I was not discussing this actually.
(1) In fact, the whole exchange started when the OP asked how to call 2
different
Alan Gauld wrote:
"David" wrote
Forwarded to the list, I would also like to understand the forward slash;
os.system("mv %s/%s %s" % (src, fnames, dst))
The slash separates the file path, src, from the filename.
Thus if src is /foo/bar/baz
and fnames is spam
then %s/%s becomes
/foo/bar/b
"David" wrote
Forwarded to the list, I would also like to understand the forward slash;
os.system("mv %s/%s %s" % (src, fnames, dst))
The slash separates the file path, src, from the filename.
Thus if src is /foo/bar/baz
and fnames is spam
then %s/%s becomes
/foo/bar/baz/spam
Another wa
25 matches
Mail list logo