"Mandar Vaze / मंदार वझे" <mandarv...@gmail.com> writes:
> Code 1: > ... > return dict(fname=fname, lname=lname, saluation=salutation, > gender=gender, addr1=addr1, addr2=addr2, > city=city, state=state, country=country) First of all, both functions are returning a single value, a single dict. So the entire discussion of "how many values should I return from a function" is irrelevant. As for which of the two code samples is better, I think it is a matter of taste. However, I should point out that in template programming (as happens in the case of Django), it is fairly common to create and return a dict containing all the values that are needed for the template. In other words, it is a pattern that people are used to; and since they're all values that are needed in the same template, it is OK to club them together like this. To me, "Code #1" is perfectly acceptable - for this use case. > Code 2: > user = {} [ 5 more citation lines. Click/Enter to show. ] > user['fname'] = fname > user['lname'] = lname > ... > ... > ... > user['country'] = country > > return dict(user=user) I don't see why doing the dict assignments into different statements is any better than simply creating the dict directly. In fact, I prefer the former (but, I would put each "key: value" pair on a line by itself), because the intent is much clearer. Also, you could have done "return user" here instead of "return dict(user=user)". Which one is better has nothing to do with python, and depends upon the template language you're using and the content of the template. navin. _______________________________________________ BangPypers mailing list BangPypers@python.org https://mail.python.org/mailman/listinfo/bangpypers