0

I have several lists that are structured as follows

list_01= [['Little Line', '15']]
list_02= [['Long Line', '20']]

Later on in the code after these lists I want to create a function that defines the creation of lines that I want to work as follows. If the items in the list equal the strings 'Little Line' and '15', it will create a little line.

def draw_line(dataset):
    if dataset[0[0]]==('Little Line'):
        left(dataset[0[1]])
        foward(25)

Later, I can then call this function as follows later on in the code:

draw_line(list_01)

to create the line. The code I've described is pretty similar to my current code and shows how I believe it should work. I understand this should probably be pretty basic code, but I'm experiencing errors and can't quite figure out how it should work.

3
  • 2
    dataset[0[0]] is not going to work, you can't index integers (0[0]). Did you mean dataset[0][0] perhaps? Why the nested format? Commented Apr 17, 2017 at 11:33
  • It seems your way of accessing the dataset is wrong. dataset[0[1]] should've been dataset[0][1]. [0[1]] is not a real index as it should have just been a number. Commented Apr 17, 2017 at 11:36
  • Please look into this answer for better understanding. Commented Apr 17, 2017 at 11:37

1 Answer 1

3

Your syntax for accessing nested lists is wrong. Instead of

dataset[0[0]]

you need to do

dataset[0][0]

But in general, a list is not a reasonable datatype for this. A dictionary would make a lot more sense:

moves = {
    "Little line": 15,
    "Long line": 20,
    # etc.
    }

and then do something like

def draw_line(dataset):
    left(dataset[0])
    forward(25)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.