[Tutor] dict(sequence) and dict(mapping)

Scott Chapman scott_list@mischko.com
Sat Apr 12 16:24:02 2003


I'm looking at help(__builtins__) in Python 2.2.1.

It shows:
    class dict(object)
     |  dict() -> new empty dictionary.
     |  dict(mapping) -> new dictionary initialized from a mapping object's
     |      (key, value) pairs.
     |  dict(seq) -> new dictionary initialized as if via:
     |      d = {}
     |      for k, v in seq:
     |          d[k] = v

I can say:
  test_dict = dict() 
to create a empty dictionary.  
How do I use the other two forms of this syntax:
test_dict = dict(mapping)
test_dict = dict(sequence)

Please give me some sample mappings and sequences that work in this syntax 
notation.

Thanks!
Scott