-5

I'm making a project in which I'm trying to represent an arduous plate by means of code, something like, each pin has different characteristics (some can be analog or digital, others with pwm etc), I thought to do it with a dictionary in which each key is a pin and the value represents if the pin is in use (1=in use or 0 = not used), until that moment I have it clear, but the problem arises when I want to assign another characteristic such as if it is analog (a 1 in second position) or if it has PWM (the value of true), something like that:

dic =={1 : [0,0,True], 2 :  [1,0,false], 3:[1,0,false], 4 [1,0,false], 5 : [1,0,false] ,6 : [1,0,false] }

a = dic.get(1)
print (a)

if I try to access it, I get something like:

 [0,0,True]

is there a way to access only one feature? for example, to find out if the pin has PWM

I've been looking but can't find anything, I apologize if my English isn't very good but I'm not a native speaker.

wjandrea
  • 28,235
  • 9
  • 60
  • 81
Felipe
  • 71
  • 6
  • Does this answer your question? [Access item in a list of lists](https://stackoverflow.com/questions/18449360/access-item-in-a-list-of-lists). I know you have a dict of lists, but it's the exact same principle. – wjandrea Aug 20 '20 at 02:13

1 Answers1

1

To find PWM:

dic = {1 : [0,0,True], 2 :  [1,0,False], 3:[1,0,False], 4:[1,0,False], 5 : [1,0,False] ,6 : [1,0,False]}

a = dic.get(1)[2]
print(a)

You can add [index] to find specific values.

NoName69
  • 172
  • 2
  • 14
  • Thank you very much for answering, now, if I wanted to overwrite that value as I could modify it, because if I put something like dic[1] = False, I change all the values and I only want to change the third one – Felipe Aug 20 '20 at 03:18
  • You would do dic[1][2] = False – NoName69 Aug 20 '20 at 04:35