This may sound like a newbie question, but I really need some help with this. I don't even know how to tag it, but I assume is just a Python question. I need to use a function that receives 5 parameters and returns 5 values:
a, b, c, d, e = function (input1, input2, input3, input4, input5)
The problem is that when I use the full variables/functions names the line is just too long, and the code looks ugly, I want to use a more fancy solution here and I was thinking on using a dict or a list so I can do this:
input_dict['param1'] = input1
input_dict['param2'] = input2
input_dict['param3'] = input3
input_dict['param4'] = input4
input_dict['param5'] = input5
ret_dict = function(input_dict)
Is there a better or "pythonic" way of improving the code quality of this kind of calls?
Thanks in advance!
You can nest lines like this
my_function(test, this, out, like, so,
something, indent)
You can expand lists into args like so
a = [1,2,3,4,5]
my_function(*a)
You can even do this
result = my_function(big, long, list,
of, args)
a,b,c,d = result
Also, PEP-8 has good recommendations on dealing with line length. – Lattyware 5 mins ago
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With