Rant (was Re: x*x if x>10
DaveM
asma61 at dsl.pipex.com
Sun Jul 27 15:29:39 EDT 2008
On Sun, 27 Jul 2008 09:28:28 -0700, Gary Herron <gherron at islandtraining.com>
wrote:
>> a = list(set(itertools.chain(*sessexam.values())))
>> a.sort() #As I write I'm wondering if I really need it sorted. Hmm...
>> return a
>Didn't someone already answer that. List addition and sum() both do
>what you want.
>
> >>> A = [1,2,3]
> >>> B = [4,5,6]
> >>> C = [7,8,9]
>
> >>> A+B+C
>[1, 2, 3, 4, 5, 6, 7, 8, 9]
True, although unsuitable for my circumstance.
> >>> sum([A,B,C], [])
>[1, 2, 3, 4, 5, 6, 7, 8, 9]
Ah. I had no luck with sum, but I hadn't realised it needed the "[]" term. I
must read about it again.
>It doesn't get any easier than that.
Not only that, but it's exactly what I was after - and fastest, too,
although speed isn't really an issue. Thank you.
DaveM
More information about the Python-list
mailing list