Shi Mu <[EMAIL PROTECTED]> wrote:
> I have have the following code:
> >>> a=[3,5,8,0]
> >>> b={}
> >>>
> How I can i assign each item in a as the key in the dictionary b
> simultaneously?
> that is,
> b={3:[],5:[],8:[],0:[]}

Explicit:

    a = [3, 5, 8, 0]
    b = {}
    for key in a:
        b[key] = []

Quicker:

    a = [3, 5, 8, 0]
    b = dict( [(k, []) for k in a] )

What behaviour do you expect when there are repeated values in the
list 'a'?

-- 
 \         "Faith may be defined briefly as an illogical belief in the |
  `\               occurrence of the improbable."  -- Henry L. Mencken |
_o__)                                                                  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to