Kepala Pening wrote:
> count = lambda x: [{y: x.count(y)} for y in set(x)]
At least for long enough lists, this is likely to be more expensive than
the approach using defaultdict. Your count() function iterates the list
(1+m) times, where m is the number of distinct words - once to create
the s
Thanks John and Kent for the guidance.
This following ends up working perfect for me - instead of print to the
console I will just write this to a text file. I will also wrap it in a
function.
from collections import defaultdict
d = {'1': ['220', '220', '220''], '2': ['220', '238', '238', '238', '
;5': [{'238': 1}, {'220': 2}], '4': [{'220': 2}], '7': [{'220': 1}],
'6': [{'238': 2}]}
----- Original Message -
From: GTXY20 <[EMAIL PROTECTED]>
To: tutor@python.org
Date: Tue, 15 Apr 2008 21:51:02
Hi Kent,
Yes I think so I think I am almost there with this:
from collections import defaultdict
d = {'1': ['220', '220', '220''], '2': ['220', '238', '238', '238', '238'],
'3': ['220', '238'], '4': ['220', '220'], '5': ['220', '220', '238'], '6':
['238', '238'], '7': ['220']}
for f, b in d.item
On 16/04/2008, GTXY20 <[EMAIL PROTECTED]> wrote:
> I currently have a dictionary like the following:
>
> {'1': ['220', '220', '220''], '2': ['220', '238', '238', '238', '238'], '3':
> ['220', '238'], '4': ['220', '220'], '5': ['220', '220', '238'], '6':
> ['238', '238'], '7': ['220']}
>
> I am tryi
GTXY20 wrote:
>
> Hi tutors,
>
> I currently have a dictionary like the following:
>
> {'1': ['220', '220', '220''], '2': ['220', '238', '238', '238', '238'],
> '3': ['220', '238'], '4': ['220', '220'], '5': ['220', '220', '238'],
> '6': ['238', '238'], '7': ['220']}
>
> I am trying to create
Hi tutors,
I currently have a dictionary like the following:
{'1': ['220', '220', '220''], '2': ['220', '238', '238', '238', '238'], '3':
['220', '238'], '4': ['220', '220'], '5': ['220', '220', '238'], '6':
['238', '238'], '7': ['220']}
I am trying to create a dictionary that would list the cur