[Tutor] Re: Tutor digest, Vol 1 #1916 - msg 8

Rob rob@uselesspython.com
Mon, 9 Sep 2002 08:14:35 -0500


I feel certain that I replied asking you for more information about what you
had tried and had in mind.

Rob

> -----Original Message-----
> From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
> Gil Tucker [ateliermobile]
> Sent: Monday, September 09, 2002 1:38 AM
> To: tutor@python.org
> Subject: [Tutor] Re: Tutor digest, Vol 1 #1916 - msg 8
>
>
>
> Hi,
>            I wonder why no one replied to my question about
> doing art with ascii types? I opnly got a reply about hacking.
> If you create stuff with ascii does that mean you are a "HACKER"
> in the negative category. Come on!
>                   Gil tucker
>
>
>
>
>
>
>
>
> ----- Original Message -----
> From: <tutor-request@python.org>
> To: <tutor@python.org>
> Sent: Sunday, September 08, 2002 4:11 PM
> Subject: Tutor digest, Vol 1 #1916 - 14 msgs
>
>
> > Send Tutor mailing list submissions to
> > tutor@python.org
> >
> > To subscribe or unsubscribe via the World Wide Web, visit
> > http://mail.python.org/mailman/listinfo/tutor
> > or, via email, send a message with subject or body 'help' to
> > tutor-request@python.org
> >
> > You can reach the person managing the list at
> > tutor-admin@python.org
> >
> > When replying, please edit your Subject line so it is more specific
> > than "Re: Contents of Tutor digest..."
> >
> >
> > Today's Topics:
> >
> >    1. question on lists (Martin Klaffenboeck)
> >    2. Re: question on lists (Sean 'Shaleh' Perry)
> >    3. Re: The Gang of Four (was: A Book for You and Me) (Magnus Lycka)
> >    4. Individual Character Count (Kyle Babich)
> >    5. Re: Individual Character Count (Danny Yoo)
> >    6. Re: Individual Character Count (Danny Yoo)
> >    7. Re: Individual Character Count (Scot W. Stevenson)
> >    8. ascii art (Gil Tucker [ateliermobile])
> >    9. Re: Re: Re: Factory classes (etc) (Magnus Lycka)
> >   10. Re: Individual Character Count (Magnus Lycka)
> >   11. Re: question on lists (Martin Klaffenboeck)
> >   12. list sorting problem (help!) (Thomi Richards)
> >   13. Re: question on lists (Gregor Lingl)
> >   14. Re: Re: Re: Factory classes (etc) (Arthur)
> >
> > --__--__--
> >
> > Message: 1
> > From: Martin Klaffenboeck <martin.klaffenboeck@gmx.at>
> > To: tutor@python.org
> > Date: 07 Sep 2002 22:49:19 +0200
> > Subject: [Tutor] question on lists
> >
> > Hello,
> >
> > I have got a list with 4 columns.  This 4 columns are:
> >
> > string1 string2 id timestamp
> >
> > So how do I store the data?  As a list or as an array:
> >
> > What I want to do with this data:
> >
> > Sort the list alphabetically (if possible _not_ case sensitive).
> > Add new entries at the right alphabetic position.
> >
> > Randomize the list (or a copy of it) and sort it back alphabetically
> > after modifying the id and the timestamp.
> >
> >
> > Whats the best way to store data for this in python?
> >
> > Thanks,
> > Martin (a newbie)
> >
> > PS.  Sorry for my bad english.
> >
> > --
> >
> >
> >
> > --__--__--
> >
> > Message: 2
> > From: Sean 'Shaleh' Perry <shalehperry@attbi.com>
> > To: tutor@python.org
> > Subject: Re: [Tutor] question on lists
> > Date: Sat, 7 Sep 2002 14:33:35 -0700
> >
> > On Saturday 07 September 2002 13:49, Martin Klaffenboeck wrote:
> > > Hello,
> > >
> > > I have got a list with 4 columns.  This 4 columns are:
> > >
> > > string1 string2 id timestamp
> > >
> > > So how do I store the data?  As a list or as an array:
> > >
> >
> > a list is for all intents and purposes an array in python.
> There are 3=20
> > grouping structures in core python -- tuple, list, dictionary.
> A tuple i=
> > s a=20
> > list which can not be changed once created a dictionary is
> equivalent to=20
> > perl's hash or C++'s map.
> >
> > > What I want to do with this data:
> > >
> > > Sort the list alphabetically (if possible _not_ case sensitive).
> > > Add new entries at the right alphabetic position.
> > >
> > > Randomize the list (or a copy of it) and sort it back alphabetically
> > > after modifying the id and the timestamp.
> > >
> > >
> >
> > list.sort() takes a function to determine sort order.  There is
> a handy=20
> > function called cmp() which is often used for this.
> >
> > Your add function is not too hard to write and the random
> module may give=
> >  you=20
> > what you want for the random stuff.
> >
> > Read through the python docs on lists and the builtin functions
> it should=
> >  get=20
> > you started.
> >
> >
> > --__--__--
> >
> > Message: 3
> > Date: Sun, 08 Sep 2002 00:04:53 +0200
> > To: Allyn Weaks <allyn.@tardigrade.net>, tutor@python.org
> > From: Magnus Lycka <magnus@thinkware.se>
> > Subject: Re: [Tutor] The Gang of Four (was: A Book for You and Me)
> >
> > At 19:55 2002-09-06 -0700, Allyn Weaks wrote:
> > >On 4/9/02, Scot W. Stevenson wrote:
> > > >"We read Knuth so you don't have to" (Tim Peters in the
> > > >"Python Cookbook") kind of book.
> > >
> > >But, but, but, Knuth is quite readable and even funny.  If you have a
> > >sufficiently warped sense of humor :-).
> >
> > And plenty of time... I tend to get tired before he
> > gets to the point. He is ... different. See also:
> >
> http://www.thinkware.se/cgi-bin/thinki.cgi/DiscussTheArtOfComputer
> Programmin=
> > g
> > (Look at the end for example of warped humour.)
> >
> >
> > --=20
> > Magnus Lyck=E5, Thinkware AB
> > =C4lvans v=E4g 99, SE-907 50 UME=C5
> > tel: 070-582 80 65, fax: 070-612 80 65
> > http://www.thinkware.se/  mailto:magnus@thinkware.se
> >
> >
> >
> > --__--__--
> >
> > Message: 4
> > Date: Sat, 7 Sep 2002 22:42:45 UT
> > From: "Kyle Babich" <kyle@sent.com>
> > To: "Tutor" <tutor@python.org>
> > Subject: [Tutor] Individual Character Count
> >
> > I'm trying (with little luck) to create a function to count how many
> > time an individual character appears in a file.  What I have so far I
> > have written on patterns I've noticed but it is still extremely buggy
> > depending on whether the character being searched for appears as the
> > first character in the file, the last, both, or neither.  Here it is:
> >
> > ####################
> > def InCharCount(location, character):
> >     subj =3D file(location, "r")
> >     body =3D subj.read()
> >
> >     body =3D body.split("\n")
> >     body =3D string.join(body, "")
> >     body =3D body.split(character)
> >
> >     last =3D len(body)
> >     last =3D last - 1
> >
> >     char =3D 0
> >     for each in body:
> >         char =3D char + 1
> >
> >     if body[0] in [""]:
> >         char =3D char - 1
> >
> >     elif body[last] in [""]:
> >         char =3D char - 1
> >    =20
> >     else:
> >         pass
> >
> >     return char
> > ####################
> >
> > Could someone please help me work the bugs out of this?  I have a
> > feeling that I'm making this harder than I need to for myself again.
> >
> > Thank you,
> > --
> > Kyle
> >
> >
> > --__--__--
> >
> > Message: 5
> > Date: Sat, 7 Sep 2002 16:17:20 -0700 (PDT)
> > From: Danny Yoo <dyoo@hkn.eecs.berkeley.edu>
> > To: Kyle Babich <kyle@sent.com>
> > cc: Tutor <tutor@python.org>
> > Subject: Re: [Tutor] Individual Character Count
> >
> >
> >
> > On Sat, 7 Sep 2002, Kyle Babich wrote:
> >
> > > I'm trying (with little luck) to create a function to count how many
> > > time an individual character appears in a file.  What I have so far I
> > > have written on patterns I've noticed but it is still extremely buggy
> > > depending on whether the character being searched for appears as the
> > > first character in the file, the last, both, or neither.  Here it is:
> >
> > Hi Kyle,
> >
> >
> > Let's take a look at the program.
> >
> > > ####################
> > > def InCharCount(location, character):
> > >     subj = file(location, "r")
> > >     body = subj.read()
> > >
> > >     body = body.split("\n")
> > >     body = string.join(body, "")
> > >     body = body.split(character)
> >
> > Hmmm...  Ok, so if our file's contents has something like "aaabbabba",
> > then if we wanted to count all the "a"'s, we could split against 'a' and
> > see how many pieces come up:
> >
> > ###
> > >>> s = "aaabbabba"
> > >>> l = s.split('a')
> > >>> l
> > ['', '', '', 'bb', 'bb', '']
> > ###
> >
> > As a result, our list won't contain any more "a"'s once we split by 'a'.
> > But it will have a bunch of empty strings, which might look silly.
> >
> > ... But those empty strings are there for a very good reason:
> we should be
> > able to rehydrate our string, and reverse the process by using join():
> >
> > ###
> > >>> 'a'.join(l)
> > 'aaabbabba'
> > ###
> >
> >
> > Your approach seems reasonable.  Once you've split the 'body' up, you
> > already have enough information to count how many of that 'character' is
> > in there: the number of 'character's should just be the number of
> > in-betweens we have in our split-up body:
> >
> >    ['',       '',        '',           'bb',        'bb',        '']
> >
> > That is, if we have a list of six elements, the number of "in-between"
> > places is just the number of commas we see in our list: 5.
> >
> > join ==>
> >
> >    '' + 'a' + '' + 'a' + '' + a + '' + 'bb' + 'a' + 'bb' + 'a' + ''
> >
> > So all you need now is to count "in-between" places.  I'll let
> you figure
> > out how to do that.  *grin*
> >
> >
> > Your approach works even if our string is initially empty:
> >
> > ###
> > >>> mystring = ""
> > >>> l = mystring.split("a")
> > >>> l
> > ['']
> > >>> "a".join(l)
> > ''
> > ###
> >
> > because when our split-up list is only one element long, there are no
> > "in-between" spots in our list, which is exactly right.
> >
> >
> >
> > Let's look at the rest of your code:
> >
> > >     last = len(body)
> > >     last = last - 1
> > >
> > >     char = 0
> > >     for each in body:
> > >         char = char + 1
> > >
> > >     if body[0] in [""]:
> > >         char = char - 1
> > >
> > >     elif body[last] in [""]:
> > >         char = char - 1
> > >
> > >     else:
> > >         pass
> > >
> > >     return char
> >
> > I'd remove this part of the code because it's making the problem too
> > complicated.  *grin* I don't think you need to do more cases based on
> > empty strings.  Empty strings in your split-up list are perfectly good:
> > you don't need to do additional case analysis on them.
> >
> >
> > Good luck to you!
> >
> >
> >
> > --__--__--
> >
> > Message: 6
> > Date: Sat, 7 Sep 2002 16:24:58 -0700 (PDT)
> > From: Danny Yoo <dyoo@hkn.eecs.berkeley.edu>
> > To: Kyle Babich <kyle@sent.com>
> > cc: Tutor <tutor@python.org>
> > Subject: Re: [Tutor] Individual Character Count
> >
> >
> > > Your approach seems reasonable.  Once you've split the 'body' up, you
> > > already have enough information to count how many of that
> 'character' is
> > > in there: the number of 'character's should just be the number of
> > > in-betweens we have in our split-up body:
> > >
> > >    ['',       '',        '',           'bb',        'bb',        '']
> > >
> > > That is, if we have a list of six elements, the number of "in-between"
> > > places is just the number of commas we see in our list: 5.
> > >
> > > join ==>
> > >
> > >    '' + 'a' + '' + 'a' + '' + a + '' + 'bb' + 'a' + 'bb' + 'a' + ''
> >
> >
> > Hi Kyle,
> >
> > Doh.  I messed up here in the diagram.  Forget those pictures above.  I
> > meant to write:
> >
> >
> >     l = ['',        '',        '',        'bb',        'bb',        '']
> >
> >     'a'.join(l) ==>
> >
> >          '' + 'a' + '' + 'a' + '' + 'a' + 'bb' + 'a' + 'bb' + 'a' + ''
> >
> >
> > instead, which tries to show better the relationship that
> join() has with
> > split().  My apologies for being sloppy about this.
> >
> >
> >
> > --__--__--
> >
> > Message: 7
> > From: "Scot W. Stevenson" <scot@possum.in-berlin.de>
> > Organization: Hexenhaus Zepernick
> > To: "Kyle Babich" <kyle@sent.com>
> > Subject: Re: [Tutor] Individual Character Count
> > Date: Sun, 8 Sep 2002 02:10:31 +0200
> > Cc: tutor@python.org
> >
> > Hello Kyle,
> >
> > > I'm trying (with little luck) to create a function to count how many
> > > time an individual character appears in a file.
> >
> > One thing I have learned in the past few months about Python is
> to always
> > consult the Module Library before even considering writing new
> code. This
> > is the "batteries included" principle that people keep talking
> about with
> > Python, and it works.
> >
> > In this case, there is actually a "count" method in the string
> module. I'm
> > assuming you have a new version of Python such as 2.2, where you don't
> > have to import the string module anymore (if not, we'll try
> again with one
> > of the older forms), so you get:
> >
> > ===============================
> > >>> mystring = 'Spam! Spam! Spam!'
> > >>> mystring.count('S')
> > 3
> > ===============================
> >
> > Or, even shorter, though it looks strange the first time you see it:
> >
> > ===============================
> > >>> 'Spam! Spam! Spam!'.count('S')
> > 3
> > ===============================
> >
> > So the short version of your function could be:
> >
> > ===============================
> > def InCharCount(location, character):
> >     subj = file(location, "r")
> >     body = subj.read()
> >     subj.close()
> >     return body.count(character)
> > ===============================
> >
> > [I just love that last line: It sounds like something out of a Python
> > version of "Apocalypse Now". And I bet you didn't even see it coming.]
> >
> > You don't really need the close(), because the Python Elves
> will do it for
> > you after the program is over, but it is considered good form because it
> > shows attention to detail and moral fiber. Note that count() will also
> > accept strings (such as 'word') and not only single characters ('w'), so
> > you get more fun for same price.
> >
> > There is one problem with this version, though: read() gives
> you the whole
> > file as one big string. Usually, this should be fine, but if
> you import a
> > very, very large file (say, some DNA sequencing data from your secret
> > T-Rex project) on a very, very small machine, this might cause trouble.
> >
> > So you might be better off reading the file line by line after all. You
> > could try this (in Python 2.2):
> >
> > ================================
> > def InCharCount(location, character):
> >     subj = file(location, "r")
> >
> >     nbr_of_char = 0
> >     for line in subj:
> >         nbr_of_char = nbr_of_char + line.count(character)
> >
> >     return nbr_of_char
> > ================================
> >
> > The "for line in subj" goes thru the file one line at a time
> very quickly,
> > and you simply add up all the times the char occurs in each line. This
> > takes care of any memory problems you might have with large files, but
> > does take longer.
> >
> > Hope this helps,
> > Y, Scot
> >
> > --
> >    Scot W. Stevenson wrote me on Sunday, 8. Sep 2002 in
> Zepernick, Germany
> >        on his happy little Linux system that has been up for 1966 hours
> >         and has a CPU that is falling asleep at a system load of 0.00.
> >
> >
> >
> > --__--__--
> >
> > Message: 8
> > Reply-To: "Gil Tucker [ateliermobile]" <gil@ateliermobile.de>
> > From: "Gil Tucker [ateliermobile]" <gil@ateliermobile.de>
> > To: <tutor@python.org>
> > Date: Sun, 8 Sep 2002 08:16:11 +0200
> > Subject: [Tutor] ascii art
> >
> >
> >
> >
> > Greetings,
> >                      I am trying to make a program that can
> > generate random ascii art forms or designs. I have tried a few
> > but they dont work.Any tip or tips. Or warnings?
> >                             gil tucker
> >
> >
> >
> >
> > --__--__--
> >
> > Message: 9
> > Date: Sun, 08 Sep 2002 10:57:15 +0200
> > To: "Arthur" <ajs@ix.netcom.com>, <tutor@python.org>
> > From: Magnus Lycka <magnus@thinkware.se>
> > Subject: Re: [Tutor] Re: Re: Factory classes (etc)
> >
> > At 21:21 2002-09-06 -0400, Arthur wrote:
> > >I am not "missing" method overloading in the sense that I feel
> Python is
> > >somehow deficient by not having it built-in.
> > ...
> > >But for what I am doing I want to build as much as I can a scripting
> > >interface that follows geometric intuitive logic, not
> programmers logic.
> > >And at the scripting interface level what things are called *is* to the
> > >essence
> > >of things. If a point is instantiated as an Intersection, if
> might be the
> > >intersection of a number of other possible elements. It is absolutely
> > >redundant
> > >both to have the Intersection classes named in accordance with what=
> >  elements
> > >they take as arguments, and then to give them those arguments
> - because in
> > >fact the arguments themselves define the kind of intersection we are
> > >trying to create.
> >
> > It's really difficult to help you when you are so abstract.
> > To be honest, I don't really understand what you are trying
> > to do. I think it would be easier if you showed a sample of
> > code.
> >
> > The thing is, that if you have the same name, you should
> > basically do the same thing. In Java or C++ you can't to
> > the same thing just once if the types or number of params
> > differ, but in Python you usually can.
> >
> > import math, cmath, operator
> >
> > # This handles any number of ints, floats or complex numbers.
> > def RootSumSquared(*args):
> >      if type(1j) in map(type, args): sqrt =3D cmath.sqrt
> >      else: sqrt =3D math.sqrt
> >      return sqrt(reduce(operator.add, map(lambda x: x*x, args)))
> >
> > RSS =3D RootSumSquared
> >
> > print RSS(3,4)
> > print RSS(0.3, 0.4)
> > print RSS(3j, 4)
> > print RSS(0.3, 4, 5j)
> > print apply(RSS, (1, )*100)
> >
> > Of cource the simple solution in Java or C++ would be to
> > cast all arguments to Complex, but note that I don't use
> > the slower complex sqrt unless I have a complex parameter.
> >
> > Would your overloaded method look very different from one
> > another? Maybe you can warp your thinking into making them
> > much more similar, and then further into being the same
> > thing?
> >
> > >Given lets say 20 classes which could take anywhere from one to
> > >five different sets of arguments, and thats a hell of a lot of
> > >if type(arg[0]):
> > >    xxx
> > >else:
> > >    yyyy
> > >
> > >to try to get right and keep straight.
> >
> > I bet it will still be much shorter than Java if you use
> > the kind of signature recognition function that I mentioned
> > previously...
> >
> > BTW, would it be possible to write a base class Overloader
> > such that:
> >
> > class X(Overloader):
> >      def add_int_int(self, a, b):
> >          return a + b
> >      def add_string_int(self, a, b):
> >          return a + str(b)
> >
> > a =3D X()
> >
> > a.add(1, 3) =3D> 4
> > a.add('a', 5) =3D> 'a5'
> > a.add('d', 'd') =3D> AttributeError
> >
> > __getattr__ will catch the calls to the undefined
> > 'add' method, but I don't know how to figure out
> > what the argument list looked like. Can that be
> > found from the Python introspection magic?
> >
> >  >>> class X:
> > ...     def x(self):
> > ...             print "Hello"
> > ...     def __getattr__(self, value):
> > ...             return self.x
> > ...
> >  >>> a =3D X()
> >  >>> a.hello()
> > Hello
> >  >>> a.bitMap()
> > Hello
> >
> > This is a little bit on the way, it the __getattr__
> > is in the base class. There are seemingly useful
> > functions in the inspect module, but they aren't so
> > easy to figure out...
> >
> >
> >
> > --=20
> > Magnus Lyck=E5, Thinkware AB
> > =C4lvans v=E4g 99, SE-907 50 UME=C5
> > tel: 070-582 80 65, fax: 070-612 80 65
> > http://www.thinkware.se/  mailto:magnus@thinkware.se
> >
> >
> >
> > --__--__--
> >
> > Message: 10
> > Date: Sun, 08 Sep 2002 11:00:26 +0200
> > To: "Scot W. Stevenson" <scot@possum.in-berlin.de>,
> >    "Kyle Babich" <kyle@sent.com>
> > From: Magnus Lycka <magnus@thinkware.se>
> > Subject: Re: [Tutor] Individual Character Count
> > Cc: tutor@python.org
> >
> > At 02:10 2002-09-08 +0200, Scot W. Stevenson wrote:
> > >You don't really need the close(), because the Python Elves
> will do it for
> > >you after the program is over, but it is considered good form
> because it
> > >shows attention to detail and moral fiber.
> >
> > Also, you don't know when the elves will take action
> > if you are using Jython. Jython uses the Java garbage
> > collection, which is not based on reference counting.
> >
> >
> > --=20
> > Magnus Lyck=E5, Thinkware AB
> > =C4lvans v=E4g 99, SE-907 50 UME=C5
> > tel: 070-582 80 65, fax: 070-612 80 65
> > http://www.thinkware.se/  mailto:magnus@thinkware.se
> >
> >
> >
> > --__--__--
> >
> > Message: 11
> > Subject: Re: [Tutor] question on lists
> > From: Martin Klaffenboeck <martin.klaffenboeck@gmx.at>
> > To: tutor@python.org
> > Date: 08 Sep 2002 13:27:09 +0200
> >
> > Am Sa, 2002-09-07 um 23.33 schrieb Sean 'Shaleh' Perry:
> >
> > >
> > > list.sort() takes a function to determine sort order.  There
> is a handy
> > > function called cmp() which is often used for this.
> > >
> > > Your add function is not too hard to write and the random
> module may give
> you
> > > what you want for the random stuff.
> >
> > Ok, that works good with
> >
> > for x in words:
> > if x[0] < newword:
> > continue
> > if x[0] > newword:
> > break
> >
> > pos = words.index(x)
> >
> > But what can I do that the words are sorted case insensitive. (No matter
> > about upper and lower case letters)?
> >
> > And how can I tell words.sort() that it should only sort the first
> > column of my 4 column list?
> >
> > Martin
> >
> > --
> >
> >
> >
> > --__--__--
> >
> > Message: 12
> > Date: Sun, 8 Sep 2002 23:41:07 +1200
> > From: Thomi Richards <thomi@thomi.imail.net.nz>
> > To: tutor@python.org
> > Subject: [Tutor] list sorting problem (help!)
> >
> > ok, i have a problem. i have a list, like this:
> >
> > ['email me','My programs','Web Design','Web Hosting']
> >
> > and i want to sort them, so i can say something like "the link 'My
> > programs' should ALWAYS appear at the top". i thought I'd use a
> > weighting system, so the 'My programs' list item would be weighted 0,
> > and so always appear at the top. the next one would be '1', then '2',
> > etc. etc. etc. i could give 'contact me' a weighting of 999, so it would
> > always appear at the bottom.
> >
> > could i ask some of you python experts to make me a simple procedure
> > which would do this?? It's for a CGI, which has to load every page, so
> > the emphasis should be on minimal size and speed.. thanks.
> >
> > --
> > The software required Win95 or better, so I installed Linux.
> > Thomi Richards,
> > thomi@imail.net.nz
> >
> >
> > --__--__--
> >
> > Message: 13
> > Date: Sun, 08 Sep 2002 14:06:08 +0200
> > From: Gregor Lingl <glingl@aon.at>
> > To: Martin Klaffenboeck <martin.klaffenboeck@gmx.at>
> > CC:  tutor@python.org
> > Subject: Re: [Tutor] question on lists
> >
> > Martin Klaffenboeck schrieb:
> >
> > >Am Sa, 2002-09-07 um 23.33 schrieb Sean 'Shaleh' Perry:
> > >
> > >
> > >
> > >>list.sort() takes a function to determine sort order.  There
> is a handy
> > >>function called cmp() which is often used for this.
> > >>
> > >>Your add function is not too hard to write and the random
> module may give
> you
> > >>what you want for the random stuff.
> > >>
> > >>
> > >
> > >Ok, that works good with
> > >
> > >for x in words:
> > > if x[0] < newword:
> > > continue
> > > if x[0] > newword:
> > > break
> > >
> > > pos = words.index(x)
> > >
> > >But what can I do that the words are sorted case insensitive.
> (No matter
> > >about upper and lower case letters)?
> > >
> >  >>> l = [["Hans",1,2,3],
> >          ["fritz",4,5,6],
> >          ["Adam",7,8,9]]
> >  >>> t = l[:]
> >  >>> t.sort()
> >  >>> t
> > [['Adam', 7, 8, 9], ['Hans', 1, 2, 3], ['fritz', 4, 5, 6]]
> >  >>> cmp("Adam","Hans")
> > -1
> >  >>> cmp("Hans","fritz")
> > -1
> >  >>> cmp("Hans".upper(),"fritz".upper())
> > 1
> >  >>> def vgl(a,b):
> >     return cmp(a[0].upper(), b[0].upper())
> >
> >  >>> t = l[:]
> >  >>> t
> > [['Hans', 1, 2, 3], ['fritz', 4, 5, 6], ['Adam', 7, 8, 9]]
> >  >>> t.sort(vgl)
> >  >>> t
> > [['Adam', 7, 8, 9], ['fritz', 4, 5, 6], ['Hans', 1, 2, 3]]
> >  >>>
> >
> > >
> > >And how can I tell words.sort() that it should only sort the first
> > >column of my 4 column list?
> > >
> > >
> > What do you mean exactly. Do you want the result for the list
> > used above to be:
> > [['Adam', 1, 2, 3], ['fritz', 4, 5, 6], ['Hans', 7, 8, 9]]
> > ???
> >
> > Gregor
> >
> > >Martin
> > >
> > >
> > >
> >
> >
> >
> >
> >
> >
> > --__--__--
> >
> > Message: 14
> > From: "Arthur" <ajs@ix.netcom.com>
> > To: <tutor@python.org>, "Magnus Lycka" <magnus@thinkware.se>
> > Subject: Re: [Tutor] Re: Re: Factory classes (etc)
> > Date: Sun, 8 Sep 2002 10:08:53 -0400
> >
> > >It's really difficult to help you when you are so abstract.
> > >To be honest, I don't really understand what you are trying
> > >to do. I think it would be easier if you showed a sample of
> > >code.
> >
> > Well actually at this point I am not so much asking for
> specific help. More
> > trying to get a better overview of certain OO concepts that are
> inherently
> > abstract, at least to me.
> >
> > >The thing is, that if you have the same name, you should
> > >basically do the same thing.
> >
> > Now this seems to be somewhere near the gist of my issue. I
> want things to
> > have the same name for objects if they end up as objects with the same
> > essential attributes.  How they get to have those attributes
> may be totally
> > different.  A Chord, for example, might be derived as the
> intersection of a
> > line and a circle, the intersection of 2 circles, the
> intersection of a line
> > and a sphere.  The key attributes of a Chord are its endpoints.
>  Depending
> > on the the kinds of geometric objects fed in as input, the routines to
> > determine those endpoints differ fundamently, but at the end I have the
> > precisely same kind of an object - whose essential attributes
> are its two
> > endpoints. They are precisely the same kinds of objects because
> if I give a
> > Chord as an argument to the creation of another geometric
> object, it is of
> > no relevance whether that Chord was orginally created by 2 circles, or a
> > sphere and a line.
> >
> > Now in my mind Java method overloading addresses this need head-on.  But
> > maybe that is where I am confused and creating confusion -
> because though I
> > had done some Java, I much prefer Python - and my Java understanding is
> > actually much more vague than my Python.
> >
> > At any rate, the algorythm I keep referring to, would be an absolutely
> > generic function to which I could feed lists of acceptable
> arguments for a
> > Class, and get, as a return, information sufficient to inform the Class
> > which specific routine it needs to call to create its essential
> attributes -
> > in the case of a Chord, its endpoints.
> >
> > My tutorial need, I guess, is some ratification that my
> understanding and
> > goals and approach are sensible.
> >
> > Art
> >
> >
> >
> >
> >
> >
> > --__--__--
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
> >
> > End of Tutor Digest
> >
> >
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>