On Tue, Jan 20, 2009 at 5:42 AM, Lie Ryan <lie.1...@gmail.com> wrote:
> > Using sys.maxint to prime minLen is overkill, of course - > > "antidisestablishmentarianism" is only 28 letters long, after all - but > > it should be larger than any word you can expect to see. This doesn't > > catch ties, though... could do that like so: > > > Other than overkill, it is wrong. If the shortest "word" is longer than > maxint it'd give wrong result. What language do you speak (or machine do you use), where the shortest word in a potential list is longer than maxint? On my machine maxint is 2,147,483,647. That's what I meant by overkill. You could just simply use the len of the first word. True dat. Requires an extra step or two, though - initializing with some impossibly huge number is quick. > The best solution though, have been answered by Kent Johnson. > Extremely terse and elegant, doesn't find ties. def MinKent(corpora=""): > words= corpora.split() > return min(words, key=len) > > print MinKent("No victim has ever been more repressed and alienated than > the truth is") > Output: No Mine returns (2, ['No', 'is'], 9, ['repressed', 'alienated']). I could be wrong - it seemed more like what the OP actually wanted, but he'd be the judge of that. -- www.fsrtechnologies.com
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor