newbie seeks advise.
phr-n2002b at NOSPAMnightsong.com
Fri Sep 20 07:46:59 CEST 2002
kodokuchef at yahoo.com (akirasugiura) writes:
> I've been learning python for about a month. I had no prior knowledge
> of programming.
> My question is, I have a tuple which is, data = (69, 40, 74, 41, 56,
> 57, 38, 58, 26, 55). How I can make a function that picks up a largest
> from this "data" tuple. If "data" was a 'List' I would be able to
> use "sort" but since sort doesn't work with tuple. I am stuck here.
The simplest way is just
m = apply(max, data)
or in newer versions of Python you can also say
m = max(*data)
If x the list (1,2,3), then apply(f,x) is the same as saying f(1,2,3).
f(*x) is another way to say the same thing.
Also, if you want to convert a tuple to a list, you can say list(data)
where data is the tuple.
More information about the Python-list