Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #58712
| References | <82328ec8-7178-4a17-abfe-13d444fab9cf@googlegroups.com> <mailman.2107.1383786254.18130.python-list@python.org> <l5eqi0$3ha$1@dont-email.me> <mailman.2114.1383794270.18130.python-list@python.org> <c6a4b69c-51ee-4367-8bf0-aefed08d7bb1@googlegroups.com> |
|---|---|
| Date | 2013-11-08 09:55 +1100 |
| Subject | Re: Show off your Python chops and compete with others |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2164.1383864966.18130.python-list@python.org> (permalink) |
On Fri, Nov 8, 2013 at 5:38 AM, Nathaniel Sokoll-Ward
<nathanielsokollward@gmail.com> wrote:
> Wow! Thanks for all the feedback everyone. This content is fresh so I appreciate everyone's comments. As opposed to responding to each post individually, I'll just lump everything in here...
Best way, I think :)
> I believe that string literals can be written with single, double, or triple quotes: http://docs.python.org/release/2.5.2/ref/strings.html
Hmm. As a general rule, can you consider aiming your quiz - and any
citations like this - at a current version of Python? I'd prefer to
see this sort of thing aimed at the 3.3 docs, though if you want to
cite 2.7 that would also be of value. But 2.5 is now quite old, and
I'd rather not get the impression that you're writing a quiz based on
an unsupported version of Python. :) Though in this particular
instance it makes no difference.
>> By the way, here's a fairly bad solution to your final question:
>>
>> array666=lambda x:b"\6\6\6" in bytes(x)
>>
>> Works for the given test-cases! Doesn't work with arrays at all,
>> despite the description.
>
> Chris, I actually really like your answer, even if it doesn't satisfy the goal in the question. I'd give it a vote for cleverness!
Heh. Do you know what the limitation of my solution is, though? As I
said, it works for the given test-cases; what sort of input will it
fail on? (And also: What's its algorithmic complexity, and what's the
complexity of a better solution?) That's why I said it's a bad
solution :)
The side comment about arrays, though: Python *does* have arrays, but
they're a different beast from what you're working with, which are
called lists. The version I posted will actually work with any
iterable, but specifying that it be a list might open up some other
options.
BTW, you're going to see a lot of criticism on the list, because
that's the natural state of things. Doesn't mean we didn't enjoy
taking the quiz. :)
In your Intermediate section:
"""Which of the following is false regarding the raw_input() and
input() built-in functions in Python?
The old raw_input() has been renamed to input() in Python 3.x
input() is equivalent to exec(raw_input())
In Python 2.x, raw_input() returns a string.
raw_input() does not exist in Python 3.x"""
Technically one of those is false, but (a) you really need to specify
versions a LOT more clearly here, and (b) the falseness is a minor
technicality; it took me a while to notice that you'd written exec
where it actually uses eval. Is that distinction really worth
highlighting in the quiz?
"""Which of the following statements is false?
Python can be used to generate dynamic web pages.
Python can be used for web development.
Python's syntax is much like PHP.
Python can run on any type of platform."""
What does *any type* of platform mean? Do you mean "any platform", and
if so, do you mean that there is no pocket calculator on which Python
doesn't run? Or is there some other "type" of platform?
>>> type(platform)
<class 'module'>
I get it. Python will run on any module. *dives for cover*
BTW, here's my chosen "bad solution" for the boss question at the end
of the intermediate section. I'm sure someone here can come up with a
worse one. Wasn't sure what should be done if all three numbers are
the same, incidentally.
def indie_three(*numbers):
seen = {}
tot = 0
for n in numbers:
seen.setdefault(n, 5)
seen[n] -= 4
tot += n * seen[n]
return tot
Note how I've generalized it to any number of input values AND to any
possible number of duplicates!
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Show off your Python chops and compete with others Nathaniel Sokoll-Ward <nathanielsokollward@gmail.com> - 2013-11-06 16:00 -0800
Re: Show off your Python chops and compete with others Andrew Cooper <root@127.0.0.1> - 2013-11-07 00:13 +0000
Re: Show off your Python chops and compete with others Roy Smith <roy@panix.com> - 2013-11-06 19:24 -0500
Re: Show off your Python chops and compete with others Andrew Cooper <root@127.0.0.1> - 2013-11-07 00:28 +0000
Re: Show off your Python chops and compete with others Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-07 00:38 +0000
Re: Show off your Python chops and compete with others Chris Angelico <rosuav@gmail.com> - 2013-11-07 11:59 +1100
Re: Show off your Python chops and compete with others Chris Angelico <rosuav@gmail.com> - 2013-11-07 12:04 +1100
Re: Show off your Python chops and compete with others John Nagle <nagle@animats.com> - 2013-11-06 17:31 -0800
Re: Show off your Python chops and compete with others Tim Chase <python.list@tim.thechases.com> - 2013-11-06 21:19 -0600
Re: Show off your Python chops and compete with others Nathaniel Sokoll-Ward <nathanielsokollward@gmail.com> - 2013-11-07 10:38 -0800
Re: Show off your Python chops and compete with others Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-07 18:48 +0000
Re: Show off your Python chops and compete with others Alister <alister.ware@ntlworld.com> - 2013-11-07 19:08 +0000
Re: Show off your Python chops and compete with others Roy Smith <roy@panix.com> - 2013-11-07 20:02 -0500
Re: Show off your Python chops and compete with others alex23 <wuwei23@gmail.com> - 2013-11-08 11:49 +1000
Re: Show off your Python chops and compete with others Roy Smith <roy@panix.com> - 2013-11-07 20:54 -0500
Re: Show off your Python chops and compete with others alex23 <wuwei23@gmail.com> - 2013-11-08 12:08 +1000
Re: Show off your Python chops and compete with others Roy Smith <roy@panix.com> - 2013-11-07 21:18 -0500
Re: Show off your Python chops and compete with others Chris Angelico <rosuav@gmail.com> - 2013-11-08 13:26 +1100
Re: Show off your Python chops and compete with others Tim Chase <python.list@tim.thechases.com> - 2013-11-07 22:05 -0600
Re: Show off your Python chops and compete with others Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-11-08 05:26 +0000
Re: Show off your Python chops and compete with others Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-08 09:23 +0000
Re: Show off your Python chops and compete with others Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-11-08 19:47 +1300
Re: Show off your Python chops and compete with others Chris Angelico <rosuav@gmail.com> - 2013-11-08 09:55 +1100
Re: Show off your Python chops and compete with others jskirst@gmail.com - 2013-11-07 11:02 -0800
Re: Show off your Python chops and compete with others Tim Chase <python.list@tim.thechases.com> - 2013-11-07 13:30 -0600
Re: Show off your Python chops and compete with others 88888 Dihedral <dihedral88888@gmail.com> - 2013-11-07 16:19 -0800
Re: Show off your Python chops and compete with others MRAB <python@mrabarnett.plus.com> - 2013-11-07 01:12 +0000
Re: Show off your Python chops and compete with others Chris Angelico <rosuav@gmail.com> - 2013-11-07 12:17 +1100
Re: Show off your Python chops and compete with others John Ladasky <john_ladasky@sbcglobal.net> - 2013-11-06 17:55 -0800
Re: Show off your Python chops and compete with others Chris Angelico <rosuav@gmail.com> - 2013-11-07 13:07 +1100
Re: Show off your Python chops and compete with others Omar Abou Mrad <omar.aboumrad@gmail.com> - 2013-11-08 09:09 +0200
Re: Show off your Python chops and compete with others Nathaniel Sokoll-Ward <nathanielsokollward@gmail.com> - 2013-11-12 09:20 -0800
csiph-web