Dictionary checking

Terry Reedy tjreedy at udel.edu
Sat May 25 17:36:12 EDT 2002


"Bjørn Ove Grøtan" <bgrotan at stud.ntnu.no> wrote in message
news:3CEFCDC4.67C1564E at stud.ntnu.no...
> I'm building a dictionary with values from a file.
>
> for each key, I have an ID, Name and Alias
> 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.

If *you* look at the file, how do *you* tell?  Answer that and then
tell program how to do same.  In order for either you or computer to
tell difference between 'ID Name' and 'ID Alias', there must either be
a field delimiter which tells you that Name is missing or some format
difference between Names and Aliases.

> Also, I want to make some output with data combined from 2
dictionaries.
> Does anyone have any examples on how to do this?

look at dict.update method

Terry J. Reedy






More information about the Python-list mailing list