Python Forum
create dictionary from **kwargs that include tuple
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
create dictionary from **kwargs that include tuple
#3
Hello,

I do exactly this in some code that I just posted on github today https://github.com/Larz60p/NLTK-Corpora-...oraData.py

There is a good example in fluent python (Luciano Ramalho - O'Reilly page 70)

from collections import defaultdict
DIAL_CODES = [(86, 'China'), (91, 'India'), (1, 'United States') ...]

country_code = {country: code for code, country in DIAL_CODES}
so in your case,
from collections import defaultdict

V = [('v1', (1,2)), ('v2', (2,3)), ('v3', (3,1)), ('v4', (4,1)), ('v5', (2,4)), ('v6', (4,5))]

Graph = {edge: tup for edge, tup inĀ  V}
Reply


Messages In This Thread
RE: create dictionary from **kwargs that include tuple - by Larz60+ - Oct-26-2016, 10:24 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to include one script into another? MorningWave 8 678 Mar-21-2024, 10:34 PM
Last Post: MorningWave
  how include a python code in notpad++ plugin akbarza 2 733 Sep-25-2023, 08:25 PM
Last Post: deanhystad
  Regex Include and Exclude patterns in Same Expression starzar 2 905 May-23-2023, 09:12 AM
Last Post: Gribouillis
  How do I instantiate a class with **kwargs? palladium 6 7,889 Feb-16-2023, 06:10 PM
Last Post: deanhystad
  Create new dictionary angus1964 6 2,236 May-08-2022, 12:43 PM
Last Post: snippsat
  Create new dictionary angus1964 2 1,346 May-06-2022, 02:14 PM
Last Post: deanhystad
  convert a named tuple to a dictionary Skaperen 13 3,775 Mar-31-2022, 07:13 PM
Last Post: Skaperen
  kwargs question Jeff_t 8 3,167 Feb-16-2022, 04:33 PM
Last Post: Jeff_t
  How to include input as part of variable name Mark17 4 2,619 Oct-01-2021, 06:45 PM
Last Post: Mark17
  Create SQLite columns from a list or tuple? snakes 6 8,996 May-04-2021, 12:06 PM
Last Post: snakes

Forum Jump:

User Panel Messages

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