str = ''
for i in self.obj:
str += '[' + self.obj[i] + ']';
Is there a way to simplify the code?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming that
self.objis a dict:If it’s a custom object implementing
__getitem__instead:Note that I don’t use
stras a variable name. You shouldn’t do this as well, because it’s a builtin function in Python.UPDATE: Regarding your last comment, you could do something like this:
Or if you prefer the (more Pythonic?)
formatmethod: