Re: [Tutor] to sort

2008-12-25 Thread Mark Tolonen
"prasad rao" wrote in message news:9e3fac840812252221pe3345bam7e3e3563e050c...@mail.gmail.com... hello I am trying to sort a list(I know there is a builtin sort method). a=[21,56,35,47,94,12] b=[] for x in a: b.append (min(a)) a.remove (min(a)) >>> a [56, 47, 94] >>> b

[Tutor] to sort

2008-12-25 Thread prasad rao
hello I am trying to sort a list(I know there is a builtin sort method). a=[21,56,35,47,94,12] b=[] for x in a: b.append (min(a)) a.remove (min(a)) >>> a [56, 47, 94] >>> b [12, 21, 35] It is not Compleating .Doing only 3 rounds.Why? By the way how can I view the builtin code

Re: [Tutor] beginsWith multiple prefixes

2008-12-25 Thread Kent Johnson
On Thu, Dec 25, 2008 at 12:46 PM, Alan Gauld wrote: > for d in os.listdir(): > if MyString(d).beginswith(): > > Which isn't that cumbersome. d is still available for > subsequent processing and acces to normal string > methods is still useful , as in: > > for d in os.listdir(): > if MyStr

Re: [Tutor] beginsWith multiple prefixes

2008-12-25 Thread Alan Gauld
"Kent Johnson" wrote You could also make this a method of a subclass of string if you prefer: class MyString(str): def beginswith(self, prefixes): for prefix in prefixes: if self.startswith(prefix): return prefix It's an appealing idea but the extra step of

Re: [Tutor] beginsWith multiple prefixes

2008-12-25 Thread Emad Nawfal (عماد نوفل)
On 12/25/08, Kent Johnson wrote: > > On Wed, Dec 24, 2008 at 4:04 PM, Emad Nawfal (عماد نوفل) > wrote: > > Hi Tutors, > > I want a function that acts like the startswith method, but can take > > multiple prefixes. As an amateur programmer, I came up with this one, and > it > > works fine, but my

Re: [Tutor] beginsWith multiple prefixes

2008-12-25 Thread Kent Johnson
2008/12/25 Alan Gauld : > You could also make this a method of a subclass of string if you prefer: > > class MyString(str): > def beginswith(self, prefixes): > for prefix in prefixes: >if self.startswith(prefix): > return prefix > > Now you can create instances of

Re: [Tutor] beginsWith multiple prefixes

2008-12-25 Thread Kent Johnson
On Wed, Dec 24, 2008 at 4:04 PM, Emad Nawfal (عماد نوفل) wrote: > Hi Tutors, > I want a function that acts like the startswith method, but can take > multiple prefixes. As an amateur programmer, I came up with this one, and it > works fine, but my experience tells me that my solutions are not alwa

Re: [Tutor] beginsWith multiple prefixes

2008-12-25 Thread Alan Gauld
"Emad Nawfal (عماد نوفل)" wrote >> I want a function that acts like the startswith method, but can >> take >> multiple prefixes. Above does a lot more work than necessary. Try: def beginsWith(word, listname): for prefix in listname: if word.startswith(prefix): return True

Re: [Tutor] beginsWith multiple prefixes

2008-12-25 Thread Emad Nawfal (عماد نوفل)
On 12/25/08, Bill Campbell wrote: > > On Wed, Dec 24, 2008, bob gailer wrote: > > Emad Nawfal ( ) wrote: > >> Hi Tutors, > >> I want a function that acts like the startswith method, but can take > >> multiple prefixes. As an amateur programmer, I came up with this one, > >> and it works fi