Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Combining arrays into dict
#4
Just my take on this:

#leds status as input
in_ledS = 17      #pin 11
in_ledXL = 18     #pin 12
in_ledXXL = 22    #pin 15
in_ledS1 = 23     #pin 16
in_ledS2 = 4      #pin 7

# maybe the values of the pins will change often
# make an array of pin names as strings
leds_arry = ['in_ledS', 'in_ledXL', 'in_ledXXL', 'in_ledS1', 'in_ledS2']
# the present values of the pins as a list
pin_value = [in_ledS, in_ledXL, in_ledXXL, in_ledS1, in_ledS2]
# the present state of the pins
leds_state = [0, 1, 0, 1, 1]
# make an empty dictionary k = pin name, value is a list for pin value and led_state
pin_value_state = {k:[0, 0] for k in leds_arry}

for i in range(len(leds_arry)):
    pin_value_state[leds_arry[i]][0] = pin_value[i]
    pin_value_state[leds_arry[i]][1] = leds_state[i]

for item in pin_value_state.items():
    print(item)
Reply


Messages In This Thread
Combining arrays into dict - by ebolisa - Sep-26-2021, 09:06 PM
RE: Combining arrays into dict - by bowlofred - Sep-26-2021, 09:20 PM
RE: Combining arrays into dict - by ebolisa - Sep-26-2021, 09:27 PM
RE: Combining arrays into dict - by Pedroski55 - Sep-26-2021, 11:44 PM
RE: Combining arrays into dict - by bowlofred - Sep-26-2021, 11:56 PM
RE: Combining arrays into dict - by deanhystad - Sep-27-2021, 02:52 AM
RE: Combining arrays into dict - by ebolisa - Sep-27-2021, 07:52 AM
RE: Combining arrays into dict - by deanhystad - Sep-27-2021, 03:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Sort a dict in dict cherry_cherry 4 80,793 Apr-08-2020, 12:25 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020