Perl Christmas Quiz

Abigail abigail at abigail.be
Tue Dec 16 08:17:10 GMT 2008


On Mon, Dec 15, 2008 at 01:29:39PM +0000, Nicholas Clark wrote:
> On Mon, Dec 15, 2008 at 01:22:49PM +0000, Avleen Vig wrote:
> > On Dec 15, 2008, at 10:04, "James Laver" <james.laver at gmail.com> wrote:
> > 
> > >On Sun, Dec 14, 2008 at 3:15 PM, Avleen Vig <avleen at gmail.com> wrote:
> 
> > >>In the spirit of sharing, I offer this solution, from your neighbours
> > >>in the Python community:
> > >>
> > >>a = ['m', 'n', 'o', 'o', 'p', 'p', 'q']
> > >>b = ['n', 'p', 'q', 'r', 'r', 's']
> > >>
> > >>def FindSetMatches(list1, list2):
> > >>for i in set(list1).intersection(set(list2)):
> > >>  print '%s min(%s, %s)' % (i, list1.count(i), list2.count(i))
> 
> > Plus I just wanted to be a snob with my four-line solution.
> 
> Yes, but can Python do it in one line?
> 
> (Sort of a serious question. Not knowing Python, but having this understanding
> that all constructions that C (etc) and Perl (etc) would delimit with {},
> Python does with whitespace indentation level, I'm figuring that some things
> in Python *have* to be done in multiple lines. For maintaining real world
> code, this is probably actually a feature, rather than a "feature")


Putting the 'for' and the 'print' statement of the above program
on one line works fine in Python.

Not sure if there's a way to put the 'def' and the body of the sub
on the same line. Just removing the newline of the above program
gives a syntax error.


Abigail


More information about the london.pm mailing list