In article <[EMAIL PROTECTED]>, Steven Bethard
<[EMAIL PROTECTED]> wrote:
> I don't speak Perl, but based on your output, I'd probably do something
> like:
>
> py> lines = ["1,2,3,4,5", "2,3,4,5", "3,4,5", "4,5", "5"]
> py> counts = {}
> py> for items in lines:
> ...for item in items.split('
John Machin wrote:
> freq_dict = {}
> ...
> if thing in freq_dict:
> freq_dict[thing] += 1
> else:
> freq_dict[thing] = 1
>
> or, less plainly,
>
> freq_dict[thing] = freq_dict.get(thing, 0) + 1
or
try:
freq_dict[thing] += 1
except KeyError:
freq_dict[thing] = 1
STeVe
--
htt
Hi All--
John Machin wrote:
>
> > how to duplicate the following bit of code using Python dictionaries.
> >
>
> [expletives deleted]
>
+1 QOTW
Metta,
Ivan
--
Ivan Van Laningham
God N Locomotive Works
http://www.andi-holmes.com/
http://www.foretec.com
Koncept wrote:
> Howdie Python folks! I am very new to Python ( 3rd day now ) and it has
> already earned its place as my fav. language to work in. I hope to
> continue, and I really would appreciate some good resources if anybody
> would care to contribute.
>
> My current head-scratcher concerns
Koncept wrote:
> #!/usr/bin/perl
>
> # Parse comma delimited lines and create a final frequency hash
> # Real example would read a file line by line
> my %dict = {};
> my @lines = ( "1,2,3,4,5", "2,3,4,5", "3,4,5", "4,5", "5" );
> foreach(@lines) { map( $dict{ $_ }++, split( "," ) ); }
> foreach(
Howdie Python folks! I am very new to Python ( 3rd day now ) and it has
already earned its place as my fav. language to work in. I hope to
continue, and I really would appreciate some good resources if anybody
would care to contribute.
My current head-scratcher concerns something I can do in Per