[Tutor] can i pass a list to a function and get one back ?
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Sun Oct 22 04:40:20 CEST 2006
> great, thanks, i have idle right here, would have been just as easy.
> sorry about that
No problem; it's cool.
>> > hey there, i was just wondering if i could get a list back from a
>> > function.
>> > something like
>> > def return_a_list(some_var):
>> > some_list = []
>> > for i in range(5):
>> > var = some_var + i
>> > some_list.append(var)
>> > return some_list
>> > is this cool ?
It's cool. *grin*
One small comment: we often don't need to use temporary variables like
'var'.
def return_a_list(some_var):
some_list = []
for i in range(5):
some_list.append(some_var + i)
return some_list
Sometimes a temporary variable is useful, and sometimes not. Here, it
seems like it's not too necessary.
Good luck!
More information about the Tutor
mailing list