[x] Search for duplicates among the existing issues (both open and closed).
Proposal
Describe the new feature clearly and concisely. If applicable, write a minimal example in Python or in pseudo-code to show input, usage, and desired output.
While looking through the examples available at the website I noticed this (in my opinion) confusing snippet of code on the example with the countries of Oceania:
countries = {
"Australasia": ["AU", "NZ"],
"Melanesia": ["NC", "PG", "SB", "VU"],
"Micronesia": ["FM", "GU", "KI", "MH", "MP", "NR", "PW"],
"Polynesia": ["PF", "WS", "TO", "TV"],
}
# Create a dictionary mapping region to country (e.g. AU -> Australasia)
region_to_country = {
region: country for country, regions in countries.items() for region in regions
}
My first thought was that this code would create a shorted dictionary with only four regions and their last listed country because of the region: country in the comprehension. However when I tested it, it ran perfectly. Several minutes later I noticed what was happening on the part of country, regions in countries.items(), which is confusing since country actually contains the four regions and regions is a list of countries.
While I understand this is not the main point of what the library does, and the code works as intended, I still think this should be changed to make it more intuitive to the reader. Since this is very mundane and the maintainer already spend the best part of a minute reading this far, I will be opening a PR to fix this myself have opened PR #264.
Prework
Proposal
While looking through the examples available at the website I noticed this (in my opinion) confusing snippet of code on the example with the countries of Oceania:
My first thought was that this code would create a shorted dictionary with only four regions and their last listed country because of the
region: country
in the comprehension. However when I tested it, it ran perfectly. Several minutes later I noticed what was happening on the part ofcountry, regions in countries.items()
, which is confusing sincecountry
actually contains the four regions andregions
is a list of countries.While I understand this is not the main point of what the library does, and the code works as intended, I still think this should be changed to make it more intuitive to the reader. Since this is very mundane and the maintainer already spend the best part of a minute reading this far, I
will be opening a PR to fix this myselfhave opened PR #264.