On Fri, 2007-01-19 at 20:05 +0000, Adam Cripps wrote:
> On 1/19/07, Simon Brunning <[EMAIL PROTECTED]> wrote:
> > On 1/19/07, Adam Cripps <[EMAIL PROTECTED]> wrote:
> > > I'm adding strings to a Set to prevent duplicates. However, the
> > > strings are meant to be in the correct order. When I add the string to
> > > the Set, the order seems to change (and I don't seem to be able to
> > > predict what order they are in).
> >
> > Sets, like dictionaries, hold their items in an arbitrary order - see
> > <http://tinyurl.com/a2nkg>.
> 
> OK - thanks for that - so it seems that using a Set will complicate
> the matter more.
> 
> Really, I want to have a set of sets which won't have any duplicates.
> An example might look something ilke this:
> 
> sums = [['1) 10 + 2 =', '12'], ['2) 13 + 4 =', '17']]
> return sums

It looks like you have embedded the numbering into your strings.  If the
numbers were removed from the strings would you still care about keeping
the strings in order?

>>> sums = set([('10 + 2 =', '12'), ('13 + 4 =', '17')])

I changed the inside lists of pairs to tuples of pairs

>>> for ndx,(query,answer) in enumerate(sums):
...     print "%d) %s %s" % (ndx+1, query, answer)
... 
1) 10 + 2 = 12
2) 13 + 4 = 17


> 
> How might I achieve this list, without the duplicates (the duplicate
> bit is the bit I'm stuck on).
> 
> Adam
-- 
Lloyd Kvam
Venix Corp

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to