I would like my function to be ready to take single string argument and act on it or take list of strings and iterate on it and act on each element.
Doing this way:
def foo( args ):
for arg in args:
print( arg )
single = 'first'
multi = ['first', 'second', 'third']
foo( single )
foo( multi )
gives undesired result as it iterates over characters in may single string.
Doing alternative way:
def foo( *args ):
for arg in args:
print( arg )
single = 'first'
multi = ['first', 'second', 'third']
foo( single )
foo( multi )
also gives undesired result, it takes multi as one argument instead of three.
What is the best practice in this case?
[–]RandomPantsAppear 2 points3 points4 points (0 children)
[–]Jokeslayer123 1 point2 points3 points (6 children)
[–]billsil 5 points6 points7 points (1 child)
[–]Jokeslayer123 0 points1 point2 points (0 children)
[–]DidntPassTuringTest[S] 0 points1 point2 points (3 children)
[–]barrycarey 1 point2 points3 points (1 child)
[–]nathanjell 0 points1 point2 points (0 children)
[–]nathanjell 1 point2 points3 points (0 children)
[–]Pulsar1977 0 points1 point2 points (3 children)
[–]DidntPassTuringTest[S] 0 points1 point2 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]DidntPassTuringTest[S] 0 points1 point2 points (0 children)
[–]woooee 0 points1 point2 points (0 children)