The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Newsgroups: comp.lang.python
From: Duncan Booth <duncan.bo...@invalid.invalid>
Date: 19 Jun 2008 12:54:31 GMT
Local: Thurs, Jun 19 2008 8:54 am
Subject: Re: advanced listcomprehenions?
Mark Wooding <m...@distorted.org.uk> wrote: Ooh. Doesn't having 5 elements make you shudder? (Even though you did > This is still inelegant, though. We can glue the results mod 3 and 5 > together using the Chinese Remainder Theorem and working mod 15 > instead. For example, > [['Fizz', 'FizzBuzz', False, None, 'Buzz'][(pow(i, 4, 15) + 1)%7] or > (A less mathematical approach would just use i%15 to index a table. But change one to avoid a repeated value.) You have 4 options for output, so for elegance that list should also have 4 elements: [[str(i), 'FizzBuzz', 'Fizz', 'Buzz'][25/(pow(i, 4, 15) + 1)%4] for i in I feel it is even more elegant with the lookup table in its natural order: [['Fizz', 'Buzz', 'FizzBuzz', str(i)][62/(pow(i, 4, 15) + 1)%4] for i in :) -- You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||