On Mon, Nov 23, 2009 at 11:14 AM, astral orange <457r0...@gmail.com> wrote:
> But back to the example, on line 104 I see there's a call to the > lookup function, passing 3 > parameters ('data', which I think is a nested dictionary, label > (first, middle, last) and name). > > But I am getting lost on line 111 after the parameters are passed in > to the lookup function. I'm > not exactly sure what it's returning The 'get' method of dictionaries returns either the value if it exists, or None. So lookup is returning either a the value from that nested dictionary (the value which will be a list of names), or None. > and when it does return, is this > assigned the the variable > 'people'? Yes. > And if so, I'm not sure what 'append(full_name)' does here. > The else statement which assigns > '[full_name]' to 'data[label][name]' is somewhat confusing as I'm > saying to myself where the heck did > '[full_name]' come "into the picture". > > Look up at line 97. The "purpose" of this code seems-- on a cursory glance-- to be to categorize peoples names into lists where their names are common. The data dictionary contains three dictionaries; one for first names, one for middle names, one for last names. Each dictionary would, over time, contain the name-part as a key and then a list of full names... So, I'd be: data['first']['Stephen'] = ['Stephen Hansen'] data['last']['Hansen'] = ['Stephen Hansen'] Then if Bob Hansen was run through the code, it'd end up as: data['last']['Hansen'] = ['Stephen Hansen', 'Bob Hansen'] At least I think that's what the code is doing. Based upon just a stare. :) (And if that's what its doing, I think it has a bug as I mentioned in a previous email; I think lines 105-108 need to be indented one level more) So, what all this code is doing is breaking apart someoen's full_name which was passed into the function originally, and seeing where to put it. That's what the for loop and lookup function calls are doing... seeing if we need a new list , or if there's an existing one to add the name to... When it decides where it goes, it puts the full_name in. --S
-- http://mail.python.org/mailman/listinfo/python-list