0
list_op = [
            method1(arg1, arg2, arg3, arg4, arg5),
            method2(arg1, arg2, arg3, arg4, arg5),
            method3(arg1, arg2, arg3, arg4, arg5),
            method4(arg1, arg2, arg3, arg4, arg5),
        ]

I have the above but I can't help but feel like it looks like a duplicate code or it's violating some best practices. What should I do here?

james pow
  • 336
  • 2
  • 11
  • Maybe putting the arguments in a tuple and [unpacking them](https://stackoverflow.com/q/3480184/10077)? – Fred Larson Nov 15 '21 at 22:37
  • This question is too broad for Stack Overflow. For improving working code, you can ask on [codereview.se] instead, but first please read [their How to Ask page](https://codereview.stackexchange.com/help/how-to-ask); for example, you need to provide context. – wjandrea Nov 15 '21 at 22:46
  • There are [No Best Practices](https://www.satisfice.com/blog/archives/5164) – Stephen C Nov 15 '21 at 22:47
  • 1
    In this case ... it is a matter of opinion whether a small amount of repetitious code is better or worse than a small amount of complexity to avoid writing repetitious code. – Stephen C Nov 15 '21 at 22:49

1 Answers1

2

Maybe something like this?

methods = [method1, method2, method3, method4]
args = [arg1, arg2, arg3, arg4]
list_op = [m(*args) for m in methods]
Riccardo Bucco
  • 13,980
  • 4
  • 22
  • 50