MultiArg assignment
Posted: Wed Oct 08, 2008 8:34 pm
Opened a ticket for this but not a discussion (ticket:38)
1. Support multiple arg assignment ( tuple unpacking) - assignment to multiple args from a list-like-thing in a single statement
as in
2. Also support multiple assignment of Key and value pairs in a for statement
3. Support multiple assignment from an IEnumeration expression in a for statement
1. Support multiple arg assignment ( tuple unpacking) - assignment to multiple args from a list-like-thing in a single statement
as in
- Code: Select all
<multi arg commaSep list> = <List expression>
a,b = 1,2 #possible syntax
a,b = fnReturns2Args() #call to a method returning a list
x,y = [1,2]
# above approx equiv to
t = [1,2]
x=t[0]
y=t[1]
list=...something generating a list/array/string...
i,j,k = list # gets first 3 elements of list
2. Also support multiple assignment of Key and value pairs in a for statement
- Code: Select all
for key, value in dict
...
3. Support multiple assignment from an IEnumeration expression in a for statement
- Code: Select all
for x,y in ..whatever_list_array_string
... do something with x and y