How to get an item from a simple set?
Steven Bethard
steven.bethard at gmail.com
Wed Nov 24 11:32:56 EST 2004
More information about the Python-list mailing list
Wed Nov 24 11:32:56 EST 2004
- Previous message (by thread): How to get an item from a simple set?
- Next message (by thread): How to get an item from a simple set?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Pete Forman wrote: > I actually wanted to append the single item to a string, Steven's > solutions work for assignment. [snip] >>>>line = 'bar ' >>>>line += iter(s).next() >>>>line > 'bar foo' Yeah, using the assignment's an extra line: >>> line_list = ['bar '] >>> item, = s >>> line_list.append(item) >>> ''.join(line_list) 'bar foo' I still tend to write the extra line in cases like this -- it guarantees that the set is really the size that I think it is, where the iter(s).next() solution will not raise an exception if the set is actually larger. Steve
- Previous message (by thread): How to get an item from a simple set?
- Next message (by thread): How to get an item from a simple set?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list