0

I have a function in first Python file to do some manipulation with two strings:

J = "aA"
S = "aAAbbbb"

def numJewelsInStones(self, J: str, S: str) -> int:
    return len(J + S)

And function in another file to check time taken (performance test for small expressions):

def check_time(function, *args):
    print(timeit.timeit(lambda: function(args)))

So on startap i get error in print(timeit.timeit(lambda: function(args))):

rating.check_time(solution.numJewelsInStones, J, S)
TypeError: numJewelsInStones() missing 1 required positional argument: 'S'

How can i pass multiple arguments to inner function?

  • 2
    You need to unpack the arguments in your call to `function`, like so: `function(*args)`. +1 for the use of type hints, are you taking a course using them? If so, and if you don't mind, where? – Nelewout Aug 04 '20 at 16:50
  • @N.Wouda thanks! It is work! I just needed to add one star before `args`. it's task from **leetcode**. Right now i did [that](https://leetcode.com/problems/jewels-and-stones/). – sqfshggy Aug 04 '20 at 18:23
  • Very nice how they're now using type hints! – Nelewout Aug 04 '20 at 19:02

0 Answers0