tags:

views:

51

answers:

2

Here's the line that throws this error

(x,neighbor) = random.sample(out_edge_list,1)
+3  A: 

You're asking for 1 unique random element. So you're getting back something like [5]. If the 5 goes into x, what goes into neighbor?

Perhaps you meant to ask for 2 elements?

(x, neighbor) = random.sample(out_edge_list, 2)
Laurence Gonsalves
@Laurence: Actually the list contains tuples
Bruce
@Bruce: Even if the list contains tuples, you're asking for a list of one element, so you're effectively saying `(x, neighbor) = [(1,2)]`. There's a difference between a list of one element and one element.
Laurence Gonsalves
@Bruce: Try using `choice` instead of `sample`. `choice` will return one random element without wrapping it in a list.
Laurence Gonsalves
A: 

Here the solution. I changed the line to

(x,neighbor) = random.sample(out_edge_list,1)[0]
Bruce
As Laurence pointed out above, that could be expressed more simply and clearly as `random.choice(out_edge_list)`.
Will McCutchen