Computer Science Canada A Python One-Line Challenge |
| Author: | wtd [ Fri Jul 29, 2005 4:44 am ] | ||||||||||
| Post subject: | A Python One-Line Challenge | ||||||||||
Sets are an unordered collection of data. They have the useful property that they only contain any given value once.
We can do fancy manipulations with sets. We can "and" two sets, and get back only the elements contained in both sets.
We can "or" sets and get any elements in either set.
And, we can "xor" (exclusive or) two sets. This gives us only elements which are not shared by the two sets.
Now, given a list of sets called "foo":
Write a single line of code which generates a new set containing all of the elements in all of the sets in "foo". No semi-colons are allowed, and the code should be readable. Lambda functions are allowed. Questions on how sets work are quite welcome. |
|||||||||||
| Author: | lyam_kaskade [ Fri Jul 29, 2005 4:56 am ] | ||||
| Post subject: | |||||
ah! I did it!
Unless I misunderstood the question
What's a lambda function? |
|||||
| Author: | MysticVegeta [ Fri Jul 29, 2005 7:42 am ] |
| Post subject: | |
Isnt "lambda" a greek alphabet, i think it comes after "kappa". lol i was bored so i memorized all of them last year in grade 8 |
|
| Author: | wtd [ Fri Jul 29, 2005 1:17 pm ] | ||||||
| Post subject: | |||||||
lyam_kaskade wrote: ah! I did it!
Unless I misunderstood the question A little bit. I may not have been clear enough, though. The one line of code has to work for any number of sets in "foo". lyam_kaskade wrote: What's a lambda function?
It's a small nameless function. A very simple example:
|
|||||||
| Author: | rizzix [ Fri Jul 29, 2005 1:27 pm ] |
| Post subject: | |
woah, lol. what just happened.. forum was messed up for a second here.. |
|
| Author: | wtd [ Tue Aug 23, 2005 4:52 pm ] | ||
| Post subject: | |||
The answer, finally.
|
|||
| Author: | wtd [ Mon Sep 05, 2005 8:31 pm ] | ||||
| Post subject: | |||||
Python programmers, heed this summons! I challenge you to take an input file like:
And generate a dictionary like:
Assigned to a variable called fileInfo, in one line of code. Oh, and no semi-colons. No square brackets either. In an ideal solution you should use only two sets of parentheses, and no curly braces. Be wary. The keys in a line of the file may contain more than one equals sign. |
|||||
| Author: | Hikaru79 [ Tue Sep 06, 2005 6:24 am ] | ||
| Post subject: | |||
? |
|||
| Author: | wtd [ Tue Sep 06, 2005 10:55 am ] | ||
| Post subject: | |||
Close.
Ok, so three sets of parentheses. |
|||
| Author: | wtd [ Tue Sep 06, 2005 1:59 pm ] | ||||
| Post subject: | |||||
Now... alter the code so it properly handles the case where the key can contain more than one equals sign. A line such as:
Would become:
|
|||||