Dictionary checking

Bengt Richter bokr at oz.net
Sat May 25 21:11:29 EDT 2002


On Sat, 25 May 2002 19:45:40 +0200, =?iso-8859-1?Q?Bj=F8rn?= Ove =?iso-8859-1?Q?Gr=F8tan?=  <bgrotan at stud.ntnu.no> wrote:

>I'm building a dictionary with values from a file.
>
>for each key, I have an ID, Name and Alias
It's hard to tell what you mean by key, but it sounds like
you have some file with possible values of ID, Name, and Alias
in each record with other fields, and perhaps you want to be able
to look up the data in the other fields using Name or lacking that,
Alias, and lacking that "do some error-handling", and you want to
do this with a Python dictionary somehow, is that right?

Or are you using ID as a key, and you wonder how to store the rest
as a value associated with the ID key so you can later tell whether
the rest has Name and/or Alias fields?

Or what? What is the file format, and what do you want to use the
dictionary for? To look up what with what?

It'll be easy if you state requirements clearly ;-)

>for some keys I have only ID and Name, some keys with
>ID and Alias, some keys with all 3 and a few keys
>with only a ID with no Name and no Alias.
>
>How can I check if Name and/or Alias contain anything. 
>If Name contains any string it's ok, but if not I want to
>use the string value of Alias - and if not any value (space/blank)
>of Alias I want to do some error-handling.
>
>
>Also, I want to make some output with data combined from 2 dictionaries.
>Does anyone have any examples on how to do this?
>
 >>> print {}.update.__doc__
 D.update(E) -> None.  Update D from E: for k in E.keys(): D[k] = E[k]

as Terry indicated.

Regards,
Bengt Richter



More information about the Python-list mailing list