Lets say I have a function that takes string arguments. But I want to dynamically generate them. There does not seem to be a way to plug this in easily. How is this done? See my example here
i_take_strings('one', 'two', 'and_the_letter_C')
s = 'one two and_the_letter_c'
i_take_strings(x for x in s.split()) #python thinks I'm retarded with this attempt
s.split()
already returns a list so you can pass it to your function as variable arguments
by prepending *
like follows:
i_take_strings(*s.split())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With