Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
creating a dictionary
#6
...?  Building dicts isn't hard.  And if your keys are all sequentially numerical, you can also use a list.
# dict
graph = {
   1: [2],
   2: [3, 4],
   3: [1],
   4: [4, 5]
}

# list
other_graph = [
   [], # 0
   [2], # 1
   [3, 4],
   [1],
   [4, 5]
]

print(graph)
print(other_graph)
Reply


Messages In This Thread
creating a dictionary - by bluefrog - Oct-25-2016, 04:30 PM
RE: creating a dictionary - by metulburr - Oct-25-2016, 04:51 PM
RE: creating a dictionary - by ichabod801 - Oct-25-2016, 05:06 PM
RE: creating a dictionary - by bluefrog - Oct-25-2016, 06:08 PM
RE: creating a dictionary - by Yoriz - Oct-25-2016, 06:19 PM
RE: creating a dictionary - by nilamo - Oct-25-2016, 06:23 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Class-Aggregation and creating a list/dictionary IoannisDem 1 1,947 Oct-03-2021, 05:16 PM
Last Post: Yoriz
  Creating a dictionary from a list Inkanus 5 3,198 Nov-06-2020, 06:11 PM
Last Post: DeaD_EyE
  Creating Dictionary form LOG /text file DG1234 7 5,544 Feb-13-2019, 08:08 PM
Last Post: DG1234
  creating a username and pword program using a #def statement and #dictionary zcode12 3 3,180 Oct-14-2018, 04:41 AM
Last Post: volcano63
  Creating dictionary from list kerzol81 4 4,378 Oct-23-2017, 11:40 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

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