Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unpack without using * (asterisk)

If I want to keep things functional, and do not want to use * in the middle, then what is the equivalent substitute function? for example,

import operator as op
print(op.eq(*map(str.upper, ['a', 'A'])))

how do I avoid using * here?

I created a function, like,

def unpack(args):
  return *args

but it gives syntax error, print(*args) works but return fails

like image 560
apostofes Avatar asked Nov 27 '25 04:11

apostofes


1 Answers

functools.reduce can be used to apply a function of two arguments to an iterable cumulatively, which would work for your example case

import operator as op
from functools import reduce
print(reduce(op.eq, map(str.upper, ['a', 'A'])))
like image 193
Iain Shelvington Avatar answered Nov 29 '25 18:11

Iain Shelvington



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!