0

I have the follow list:

my_list = [
 [0, 0, [21, 24]],
 [0, 1, [2, 13]],
 [0, 3, [1, 15]],
 [0, 4, [1, 6]],
 [0, 6, [11]],
 [0, 7, [1]],
 [1, 0, [3, 4, 10, 17]],
 [1, 1, [1, 15, 19, 24]],
 [1, 2, [1]],
 [1, 3, [5, 6, 18]],
 [1, 4, [15, 24, 25]],
 [1, 5, [10, 22]],
 [1, 6, [16, 30, 31]],
 [2, 0, [7, 20]],
 [2, 1, [5]],
 [2, 3, [11, 14]],
 [2, 4, [5, 10]],
 [2, 5, [15]],
 [2, 6, [6, 10]],
 [2, 7, [12]],
 [3, 0, [11, 18]],
 [3, 2, [2, 22]],
 [3, 5, [8]],
 [3, 6, [15]],
 [3, 7, [5]]
]

I want to retrieve the follow data:

[x,y,[z]][x+1,y+1,[z]][x+2,y+2,[z]][x+3,y+3,[z]]

should get:

[0, 3, [1, 15]],     
[1, 4, [15, 24, 25]],
[2, 5, [15]],      
[3, 6, [15]],       

where x is a index of character in a word, y is line number and z is column number. z as you can see can be more than 1 option

final = [(i,j,) for i,j in my_list if i[0]==j[0] and i[1]==j[1]+1 and i[2]==j[2]]

getting ValueError: too many values to unpack

3
  • 1
    What's your expected output? There are other issues with your code as well (getting int object is unsubscriptable now). Commented Apr 30, 2016 at 20:13
  • what is character - all your values are integers? And what element do you want to get/receive? Commented Apr 30, 2016 at 20:16
  • edit the question the final result should be:[0, 3, 15], [1, 4, 15,], [2, 5, 15], [3, 6, 15], Commented May 1, 2016 at 19:16

1 Answer 1

2

Each element of my_list has three elements which you are trying to unpack into 2. That's too many.

>>> i, j = [0, 0]
>>> i, j = [0, 0, 1]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: too many values to unpack
>>> i, j = [0, 0, [21, 24]]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: too many values to unpack
>>> i, j, k = [0, 0, [21, 24]]
>>> i
0
>>> j
0
>>> k
[21, 24]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.