Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Combining arrays into dict
#7
Thank you all for helping and I apologize for not being clear in my post, I was trying to be brief.
This' what I was trying to achieve:
I've a Raspberry controlling some relays and reading the status of some digital lines (GPIO). A bidirectional communication is taken place between the board and the phone's app via mqtt's subscribe/publish.
So, in order for the app to display the info (LEDs ON/OFF) needs to subscribe to a string (dictionary) showing the LED name and its state. The array, leds_state is updated every 2 seconds and the dictionary string is published every 3 seconds.
The code below seems to solve that problem for now.
Thanks again.

def gen_dict_string():
    # set LEDs names
    leds = ["in_ledS", "in_ledXL", "in_ledXXL", "in_ledS1", "in_ledS2"]
    # combine LED name with its state
    pub_dict = dict(zip(leds,leds_state))
    # print(pub_dict)
    return pub_dict
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,974 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