[Tutor] len(l) as loop index
Kirby Urner
urnerk@qwest.net
Thu, 04 Apr 2002 14:33:13 -0800
At 07:26 AM 4/4/2002 -0800, I wrote:
>So, final form:
>
>def sort(thelist): # called from various functions
> thelist.sort()
> return thelist
>
>def edges(face):
> edges = []
> for i,j in zip(face,face[1:]+[face[0]]):
> edges.append(sort(list((i,j))))
> return edges
>
> >>> edges(['A','C','D','E'])
>[['A', 'C'], ['C', 'D'], ['D', 'E'], ['A', 'E']]
>
>There would be other forms of the above
Such as:
def edges(face):
def sort(alist):
alist = list(alist) # might have been a tuple
alist.sort()
return alist
return [sort(alist) for alist \
in zip(face,face[1:]+[face[0]])]
>>> edges(['A','C','B','E'])
[['A', 'C'], ['B', 'C'], ['B', 'E'], ['A', 'E']]
Kirby