Re: [Tutor] Str method

2012-11-05 Thread Alan Gauld
On 05/11/12 01:52, Oscar Benjamin wrote: On 5 November 2012 01:45, Ashley Fowler wrote: I'm trying to initialize a list to several elements using the string method. I have some idea that you use a for loop I suppose... It will help if you work on getting your terminology clearer. Computing i

Re: [Tutor] Str method

2012-11-04 Thread Dave Angel
On 11/04/2012 09:01 PM, Ashley Fowler wrote: (You top-posted, so I have to remove all the historical context, or it'll remain out of order) > I have code for a Set ADT. The Set ADT is a container that stores a > collection of values or elements. > > > > > Below is some of my code...I have run in

Re: [Tutor] Str method

2012-11-04 Thread Ashley Fowler
Cc: tutor@python.org Subject: Re: [Tutor] Str method On 5 November 2012 01:45, Ashley Fowler wrote: > I'm trying to initialize a list to several elements using the string > method. I have some idea that you use a for loop I suppose... > > Could anybody help me out? I'm afraid not

Re: [Tutor] Str method

2012-11-04 Thread Dave Angel
On 11/04/2012 08:45 PM, Ashley Fowler wrote: > I'm trying to initialize a list to several elements using the string method. > I have some idea that you use a for loop I suppose... > > Could anybody help me out? > > list has no string method, at least in the versions I tried.Could you perhaps

Re: [Tutor] Str method

2012-11-04 Thread Oscar Benjamin
On 5 November 2012 01:45, Ashley Fowler wrote: > I'm trying to initialize a list to several elements using the string > method. I have some idea that you use a for loop I suppose... > > Could anybody help me out? I'm afraid not. Your question is too vague for anyone receiving your message to kno

[Tutor] Str method

2012-11-04 Thread Ashley Fowler
I'm trying to initialize a list to several elements using the string method. I have some idea that you use a for loop I suppose... Could anybody help me out? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://

Re: [Tutor] Str Method

2012-11-01 Thread eryksun
On Thu, Nov 1, 2012 at 8:19 PM, Steven D'Aprano wrote: > > s = str(self._theElements) > s = s.replace("[", "{").replace("]", "}") > return s > > > Another way is to build the string yourself: > > s = ', '.join(str(item) for item in self._theElements) > return '{' + s + '}' Or

Re: [Tutor] Str Method

2012-11-01 Thread Steven D'Aprano
On 02/11/12 02:34, Ashley Fowler wrote: Question is how do you implement the "curly brackets" in my str method? This is what I have so far... def __init__( self, *initElements ): self._theElements = list() def __str__(self): return self._theElements __str__ should return a strin

Re: [Tutor] Str Method

2012-11-01 Thread eryksun
On Thu, Nov 1, 2012 at 4:12 PM, bob gailer wrote: > > Why not create theElements as a set to start with? > what is Set ADT? is it important that we know that? I suppose it's an implementation of the set abstract data type (i.e. operations such as add, union, difference): http://en.wikipedia.org

Re: [Tutor] Str Method

2012-11-01 Thread Mark Lawrence
On 01/11/2012 15:34, Ashley Fowler wrote: Hello I am trying to add a str method to a Set ADT implementation to allow a user to print the contents of a set. However the resulting string should look like that of a list. except I am suppose to use curly brackets to surround the elements. For an

Re: [Tutor] Str Method

2012-11-01 Thread bob gailer
On 11/1/2012 11:34 AM, Ashley Fowler wrote: Hello I am trying to add a str method to a Set ADT implementation to allow a user to print the contents of a set. However the resulting string should look like that of a list. except I am suppose to use curly brackets to surround the elements. For a

Re: [Tutor] Str Method

2012-11-01 Thread Alan Gauld
On 01/11/12 15:34, Ashley Fowler wrote: Hello I am trying to add a str method to a Set ADT implementation to allow a user to print the contents of a set. However the resulting string should look like that of a list. except I am suppose to use curly brackets to surround the elements. For an examp

[Tutor] Str Method

2012-11-01 Thread Ashley Fowler
Hello I am trying to add a str method to a Set ADT implementation to allow a user to print the contents of a set. However the resulting string should look like that of a list. except I am suppose to use curly brackets to surround the elements. For an example... >>> set1 = Set() >>> print(set1)