I need to write a decorator, which delete whitespaces from the start and end of the strigs, which are given like an arguments of another function. At first i tried to write just a function which use strip
, but it remakes only first given arg, when i need them all. join
needed because without it function returns tuple.
def NewFunc(*strings):
newstr = ' '.join([str(x) for x in strings])
return newstr.strip()
print(NewFunc(' Anti ', ' hype ', ' ajou! '))
and it returns: Anti hype ajou!
when i need:Anti hype ajou!
what to change?
strip
only removes leading and trailing whitespace, and you are only strip
ping the final result. You must strip
each element before join
ing them, and this can be done in the list comprehension:
def NewFunc(*strings):
newstr = ' '.join([str(x).strip() for x in strings])
return newstr
The str(x)
is a bit unnecessary, but I don't know, maybe you are going to pass in int
s or something.