5

In Python, I have a dict has pertinent information

arrowCell = {'up': False, 'left': False, 'right': False}

How do I make an array with i rows and j columns of these dicts?

3
  • 1
    List out the expected output array? Commented Oct 10, 2015 at 7:28
  • what do you mean? Basically I want an ndarray of i rows and y columns of these dicts, I'll access them by index to change the False values to True as needed Commented Oct 10, 2015 at 7:32
  • Right, so how must the ndarray look like for the sample arrowCell listed in the question? Commented Oct 10, 2015 at 7:33

2 Answers 2

1

How to make a two dimensional i & j is explained really well on the site already at this: How to define two-dimensional array in python link.

Hope this helps, cheers!

Sign up to request clarification or add additional context in comments.

Comments

0

Although your problem isn't clear but if you want keys and values of dictionary in form of ndarray you can try this:

l = {'up': False, 'left': False, 'right': False}
a = []
for key, value in l.iteritems():
    temp = [key,value]
    a.append(temp)

result of that will be :

>>> a
[['right', False], ['up', False], ['left', False]]

or you can just try l.items(), result of which will be :

>>> l.items()
[('right', False), ('up', False), ('left', False)]

hope that helps and link given above gives you best way to define two dimensional array.

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.