Am Tue, 20 Jan 2009 09:33:40 -0600
schrieb "Paul McGuire" :
No need for a defaultdict, all dicts have a setdefault method that
works fine for this assign an empty dict/list as starting point problem:
wordlendict = {}
for w in words:
wordlendict.setdefault(len(w), []).append(w)
try:
minle
On Tue, Jan 20, 2009 at 3:14 PM, Marc Tompkins wrote:
> On Tue, Jan 20, 2009 at 11:23 AM, Lie Ryan wrote:
>
>> what I meant as wrong is that it is possible that the code would be used
>> for a string that doesn't represent human language, but arbitrary array
>> of bytes. Also, it is a potential s
On Tue, Jan 20, 2009 at 11:23 AM, Lie Ryan wrote:
> what I meant as wrong is that it is possible that the code would be used
> for a string that doesn't represent human language, but arbitrary array
> of bytes. Also, it is a potential security issue.
This is something I need to know, then - sys
On Tue, 20 Jan 2009 09:20:22 -0800, Marc Tompkins wrote:
> On Tue, Jan 20, 2009 at 5:42 AM, Lie Ryan 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
On Tue, Jan 20, 2009 at 5:42 AM, Lie Ryan 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 t
On Tue, Jan 20, 2009 at 10:33 AM, Paul McGuire wrote:
> "Finding the shortest word among a list of words" sounds like something of
> a
> trick question to me. I think a more complete problem statement would be
> "Find the list of words that are the shortest", since there is no guarantee
> that t
"Finding the shortest word among a list of words" sounds like something of a
trick question to me. I think a more complete problem statement would be
"Find the list of words that are the shortest", since there is no guarantee
that the list does not contain two words of the same shortest length. I
On Mon, 19 Jan 2009 19:13:32 -0800, Marc Tompkins wrote:
> 2009/1/19 John Fouhy
>
>> 2009/1/20 Emad Nawfal (عماد نوفل) : Of course,
>> this is not necessarily the best answer for your particular problem.
>> The problem with sorting is that you have to look at some elements more
>> than once. F
On Tue, Jan 20, 2009 at 7:13 AM, Emad Nawfal (عماد نوفل)
wrote:
> 2009/1/20 Kent Johnson
>> decorate-sort-undecorate is pretty much obsolete since the key=
>> parameter was added to sort() in Python 2.4.
> When you say that something is obsolete, what does this mean? Is that just
> because there
2009/1/20 Kent Johnson
> On Mon, Jan 19, 2009 at 9:47 PM, Emad Nawfal (عماد نوفل)
> wrote:
>
> > Thanks John for this. Although the decorate-sort-undecorate idiom looks
> so
> > natural to me now, I don't think I would have found it on my own. I have
> > that deja vu effect towards it.
>
> decor
On Mon, Jan 19, 2009 at 9:47 PM, Emad Nawfal (عماد نوفل)
wrote:
> Thanks John for this. Although the decorate-sort-undecorate idiom looks so
> natural to me now, I don't think I would have found it on my own. I have
> that deja vu effect towards it.
decorate-sort-undecorate is pretty much obsole
2009/1/19 John Fouhy
> 2009/1/20 Emad Nawfal (عماد نوفل) :
> Of course, this is not necessarily the best answer for your particular
> problem. The problem with sorting is that you have to look at some
> elements more than once. For short lists, it's not a problem, but it
> can slow you down on
2009/1/19 John Fouhy
> 2009/1/20 Emad Nawfal (عماد نوفل) :
> > Hello tutors,
> > I need to find the shortest / longest word(s) in a sequence of words.
> I've
> > done this and it works, but I'm wondering whether this is a good way:
> words = "man woman children he".split()
> words
> > [
2009/1/20 Emad Nawfal (عماد نوفل) :
> Hello tutors,
> I need to find the shortest / longest word(s) in a sequence of words. I've
> done this and it works, but I'm wondering whether this is a good way:
words = "man woman children he".split()
words
> ['man', 'woman', 'children', 'he']
Hello tutors,
I need to find the shortest / longest word(s) in a sequence of words. I've
done this and it works, but I'm wondering whether this is a good way:
>>> words = "man woman children he".split()
>>> words
['man', 'woman', 'children', 'he']
>>> lens = [len(word) for word in words]
>>> lens
[
15 matches
Mail list logo