Track outages and protect against spam, fraud, and abuse
Measure audience engagement and site statistics to understand how our services are used and enhance the quality of those services
If you choose to “Accept all,” we will also use cookies and data to
Develop and improve new services
Deliver and measure the effectiveness of ads
Show personalized content, depending on your settings
Show personalized ads, depending on your settings
If you choose to “Reject all,” we will not use cookies for these additional purposes.
Non-personalized content is influenced by things like the content you’re currently viewing, activity in your active Search session, and your location. Non-personalized ads are influenced by the content you’re currently viewing and your general location. Personalized content and ads can also include more relevant results, recommendations, and tailored ads based on past activity from this browser, like previous Google searches. We also use cookies and data to tailor the experience to be age-appropriate, if relevant.
Select “More options” to see additional information, including details about managing your privacy settings. You can also visit g.co/privacytools at any time.
Dictionaries are the key data structure in Python and you cannot avoid them. Find out how it all works in this extract from Programmer's Python: Everything is Data.
Programmer's Python
Everything is Data
Is now available as a print book: Amazon
Contents
Python – A Lightning Tour
The Basic Data Type – Numbers
Extract: Bignum
Truthy & Falsey
Dates & Times
Sequences, Lists & Tuples
Strings
Extract Unicode Strings
Regular Expressions
The Dictionary
Extract The Dictionary ***NEW!!!
Iterables, Sets & Generators
Extract Iterables
Comprehensions
Extract Comprehensions
Data Structures & Collections
Bits & Bit Manipulation
Bytes
Extract Bytes And Strings
Extract Byte Manipulation
Binary Files
Text Files
Creating Custom Data Classes
Python and Native Code
Extract Native Code
Appendix I Python in Visual Studio Code
Appendix II C Programming Using Visual Studio Code
<ASIN:1871962765>
<ASIN:1871962749>
<ASIN:1871962595>
<ASIN:187196265X>
The sequence types are useful, but sometimes they don’t quite do what you want to. You can think of a sequence as associating integers to values:
0 → value, 1 → value
and so on.
Sometimes what you really need is a way to store a value in association with a more general data type than an integer. That is, you need to store values in association with specific key data:
key1 → value, key2 → value
and so on.
where key1 and key2 are almost any object. To do this we need to use a mapping type and the only standard mapping type that Python currently supports is the dictionary.
The Python dictionary is also known as an associative array or hash table. None of the names are particularly accurate or informative and they tend to color the way people think of the data structure. For example, in this case the dictionary isn't anything to do with putting things into alphabetic order. So let's try and forget what we call it and concentrate on what it does.
Basic use
A dictionary is a “machine” that you can use to store things in such a way that you can always find them again and find them very quickly. For example, suppose you want to keep track of how old people are. You can do this using a dictionary with almost no additional code.
For example to store a person's age you would use:
age = {}
age["Lucy"] = 19
The first instruction sets age to be an empty dictionary – it’s the curly brackets that make it a dictionary, just as square brackets make a list. After you have created an empty dictionary you can then store something in it, which is what the second line does.
To get Lucy's age back all we have to do is:
print age["Lucy"]
The dictionary is a machine that, when you give it two pieces of data – a key and a value, it stores the value in association with the key. If later you give it the key, it gives you the value you stored earlier. Notice that we use indexing, as in the case of the list, using square brackets. The only difference is that for a list the key has to be integer and is usually called the index and for a dictionary it can be any hashable object and we generally call it the key.
The value can be any type of data that you care to work with, and this is one of the powerful features of a dictionary.
So to summarize:
dict[key] = value
You retrieve it using:
dict[key]
You can also create new dictionaries using the dict constructor:
dict() Creates an empty dictionary
dict(d) Creates a copy of the dictionary d
dict(iterable) Creates a new dictionary from the iterable
Each element of the iterable used to create a dictionary must be an iterable with two elements – the key and the value. A list, a tuple and a dictionary are all examples of iterables. which are covered in the next chapter.
The most commonly used is the final form of the constructor with the iterable being a list of (key.value) tuples. For example:
creates a dictionary with names as keys and ages as values. Notice that the list of tuples could just as easily be a tuple of tuples or a tuple of lists. The dict constructor using an iterable is very flexible.
If a dystopia is a place where everyone, or at least someone, lives in abject misery and terror, then most cows, fishes, forests, and humans, right now, today, are living in completely non-imaginary dystopias. The human species’ ravenous egocentrism is the landfill on which such hells are built. The landfill, in turn, consists of dregs of a crumbling but toxic myth; that tall and ancient tale according to which Homo sapiens are the world’s born rulers with the right to consume everything that exists. In the anthropocentric attitude are the social values which enable humanity’s crimes against not-just-human life. Without a thought for the majority of Earth’s inhabitants which, because they are not human, have little to no say in their own fate, our ecocidal behaviors have made an incurable mess of Earthbound existence.
In my novel The Box, the dominant entities are neither humans nor humanoids, not even animals, but limbless, mindless, voiceless things. The human characters stumble and squabble, create and steal and love and die, because ordinary things like cabinets, packages, trains, and snowflakes are the way they are. People exist at things’ mercy, empowered by them and powerless against them. Where characters’ ability to make changes to their world, or even to perceive what is happening around them, is curtailed and overwhelmed by the weather and an unintelligible trinket-size box—such a story’s central actors are not its humans. From their various points of view, their vulnerability makes their world a hell.
The diverse narrative voices of The Box are inspired by literature in translation from around the world, including some of the books on my list. Written in Asia, Eastern Europe, and the southern Americas, some of these dystopias don’t seem especially wretched, at least at first. But in these visionary works, attempts to conquer all existence in the name of anthropocentrism—whether with wars or industries, whether capitalist or communist—must fail. Instead, worlds themselves are the agents of change and wielders of power: humans subsist at the mercy of the plants, animals, buildings, chairs, particles, weather patterns which comprise the worlds they live in and create their inner worlds. World and character become mutually porous, with the result sometimes that language spills out of familiar structures into overwhelming lists, fateful fragments and recursions.
The Taiga Syndrome by Cristina Rivera Garza, translated from Spanish by Suzanne Jill Levine and Aviva Kana
A failed detective tracks a runaway couple to the taiga, Siberia’s fabled forest. The woods seem to infect people with madness as if through some black magic or undiagnosed toxicity—or as if being hacked to pieces for industrial resources has driven the land itself insane. Children turn wolfish, feral, possessed by a compulsion to run away and keep running. So vast is the forest that there’s nowhere to which humans can escape and hope to survive. Garza’s narrative is full of gaps, fragments, broken lines; like the taiga itself, it generates more shadow than clarity. The former Soviet Union, especially the Siberian province, is a popular model for dystopias in several languages.
The Factory by Hiroko Oyamada, translated from Japanese by David Boyd
The factory seems the opposite of dystopian: a workplace prestigious and welcoming, manufacturing popular everyday products. But to three highly qualified new hires, the place embodies a massive inside joke: seemingly intelligible, absolutely nonsensical. In fact, colleagues communicate primarily in inside jokes, so the general jollity is a perfect hell for newcomers. The newbies are given mind-numbing busywork, the obvious pointlessness of which destroys their self-esteem even as everyone around them seems content. It’s as if a city’s worth of intelligent humans is being fattened up on ennui and empty jokes. But to what purpose? Has it anything to do with the bizarre birds, reptiles, and rodents which exist only on factory premises? On what does the factory feed?
Radiant Terminus by Antoine Volodine, translated from French by Jeffrey Zuckerman
Dregs of the Second Soviet Union flee to the Siberian wilderness when a century of fighting ends in near total annihilation. Almost nothing survives the nuclear catastrophe, a result of the war and widespread over-exploitation of nuclear energy. Zombies, glowing almost-corpses, post-communist witches—leftovers of the once dominant human species—eke out a sub-existence as prisoners of feral plants and radioactive garbage. As scraps of Soviet rhetoric redden their memories, Volodine buries the characters in lists of weeds and detritus. The world’s invisible rulers are winds and airborne dreams, moods of insane nuclear cores imprisoned in abandoned reactors. Nuclear particles, ubiquitous and without mercy, determine who survives, how they suffer, even what they are.
The Besieged City by Clarice Lispector, translated from Portuguese by Johnny Lorenz and Benjamin Moser
The city of São Geraldo eases into the twentieth century, gradually replacing horses with automobiles and small-town sleepiness with urban bustle. Not dystopia but progress, so it seems. But as São Geraldo becomes all asphalt, noise, and scaffolding, the city molds Lucrécia into what she cannot bear to be: a cog in the machine, or rather, oil for the men who build and constitute the growing capitalist machine. As Lispector describes with characteristic obliqueness, Lucrécia understands much more than she realizes: she intuits her damnation to a life of ornamental thinghood. Trapped within the trinket that São Geraldo wants her to be is the animal she is at heart: the wild horse for whom “progress” has no place.
Baron Wenckheim’s Homecoming by László Krasznahorkai, translated from Hungarian by Ottilie Mulzet
Baron Wenckheim returns from Argentina, fleeing debts and other difficulties, to the bleak Hungarian township of his birth, which everyone else is trying to escape. The town celebrity flees as far as the outskirts, defends his weedy shack with a shotgun. Nobody else gets any farther. Krasznahorkai’s interminable sentences flood the characters in their personal voids. Soon the Baron yearns for exile; but for one reason or another, escaping his hometown just isn’t possible. The train never comes, there’s no gasoline, the buildings and infrastructure are crumbling; everybody is oppressed by decrepitude, poverty, incompetence: accomplishing anything at all is next to impossible as the overabundant absences of things make the town a prison.
The Memory Police by Yoko Ogawa, translated from Japanese by Stephen Snyder
Things are disappearing from the island. Birds, roses, calendars, stamps, ships, perfume. In the instant of something’s vanishing, everyone immediately forgets what it was and how it made them feel. Then they forget that they’ve forgotten. It’s as if, for example, maps never existed; as if the very idea of maps never occurred to anyone. The extinctions are deliberate: things are disappeared. Humans who forget to forget are arrested by the Memory Police. If your cat fails to unhappen when, by methods unknown, mysterious authorities decree the disappearance of “the cat” as concept, species, and memory, then someone will come for poor kitty, you needn’t worry—just as long as you forget.
City of Torment by Daniela Hodrová, translated from Czech by Véronique Firkusny and Elena Sokol
This is the Prague that no one wants to remember; the dingy Prague of poor people whose role in history is to be mowed down. It’s the Prague of living things: the swivel chair as portal to other Pragues, the tailor’s mannequin and stone angel yearning for love. It’s also the Prague that refuses to finish dying. Ghosts populate the pantry in the apartment where a woman relives her abandonment again and again. The living are trapped in spirals of déjà-vu or obsessed with the non-place between their Prague and the ghosts’. Faintly shimmering is the Prague that might have been, where events that did not happen are almost happening. Or are the Pragues of imagination and reality becoming confused?
The Tidings of the Trees by Wolfgang Hilbig, translated from German by Isabel Fargo Cole
On the communist side of the Berlin Wall, a disillusioned factory worker wanders in the garbage dump which, ever expanding, has already engulfed the forest and neighboring village. Shadowy “garbagemen,” a red-faced vulturine figure in black rags, and hosts of mannequins outcast from shop windows populate the dump, voicelessly haunting one another. The longer our narrator spends in the dump, taking up a sort of residence among the junk, the more the junk infects his outlook with junk’s existential (dis)qualities. Everything in existence starts to resemble waste and wasting: East Germany thrown out of the world like so much trash; history itself is time’s cremated castoffs; storytelling, for our narrator, is but a “routine of crossing out words.”
To the Warm Horizon by Jin-Young Choi, translated from Korean by Soje
In another future haunted by the former Soviet Union, Koreans fleeing a pandemic migrate en masse into Russia via Vladivostok. The refugees are overwhelmed by the vastness of the land, the deadly cold, the monotony of the flat and treeless view, and above all the sense of hostile emptiness pervading the region. It’s internal, too, this emptiness, for the characters have lost everything; emptiness infects their very voices with terseness and bleak repetitions. The remnants of a city, which seems to be destroying and rebuilding itself at the same time, turn out to be the splitting image of the 1930s’ Soviet gulags, complete with senseless slogans extolling forced labor.
Roadside Picnic by Arkady and Boris Strugatsky, translated from Russian by Olena Bormashenko
Capitalist extractivism is in full swing in the North American city beside the Zone: a garbage dump left behind by extraterrestrials. On the aliens’ technological detritus, the city’s humans grow rich. Cars no longer need gas or electricity: simply place upon your dashboard a “spacell” or “perpetual battery.” Like living cells, spacells reproduce by division. Many things of the Zone conduct themselves as living things, even as they cannot be. Antennas, as if for televisions, grow hair and defend themselves with violence. Corpses and dismembered limbs acquire “autonomous viability.” Gravity itself seems to grab things and eat them. The Zone curses those who visit: disaster follows them everywhere (hence the city’s emigration ban), and their offspring outgrow their humanity, becoming who knows what.
Take a break from the news
We publish your favorite authors—even the ones you haven't read yet. Get new fiction, essays, and poetry delivered to your inbox.
YOUR INBOX IS LIT
Enjoy strange, diverting work from The Commuter on Mondays, absorbing fiction from Recommended Reading on Wednesdays, and a roundup of our best work of the week on Fridays. Personalize your subscription preferences here.
Track outages and protect against spam, fraud, and abuse
Measure audience engagement and site statistics to understand how our services are used and enhance the quality of those services
If you choose to “Accept all,” we will also use cookies and data to
Develop and improve new services
Deliver and measure the effectiveness of ads
Show personalized content, depending on your settings
Show personalized ads, depending on your settings
If you choose to “Reject all,” we will not use cookies for these additional purposes.
Non-personalized content is influenced by things like the content you’re currently viewing, activity in your active Search session, and your location. Non-personalized ads are influenced by the content you’re currently viewing and your general location. Personalized content and ads can also include more relevant results, recommendations, and tailored ads based on past activity from this browser, like previous Google searches. We also use cookies and data to tailor the experience to be age-appropriate, if relevant.
Select “More options” to see additional information, including details about managing your privacy settings. You can also visit g.co/privacytools at any time.
With fall almost here, it’s time once again for all good fans to root for their favorites – favorite words that is. And since it is now actually meteorological fall (the months of September. October and November), it’s officially time for Dictionary.com’s “Fall 2023 Collection of Dictionary Additions.”
As is the case with virtually every good lexicon, Dictionary.com doesn’t proscriptively endorse or prohibit words and terms, but rather “document(s) their use in the real world. We are descriptive – we describe language as it is really used (not just how we or others may wish it would be used).”
Without further adieu, here (in no particular order) are some of my favorites from the dictionary’s 566 new autumn entries and 348 new definitions.
A “nepo baby” is defined as “a celebrity with a parent who is also famous, especially one whose industry connections are perceived as essential to their success.” Obviously the term comes from “nepotism,” which is the practice of granting an advantage, privilege or position to relatives or close friends in an occupation or field. You know, like when a U.S. president names his daughter and her husband to be his senior advisors.
In these days of texts and emails (and after a few failed attempts at humor on my part), “Poe’s Law” seems like a really good idea. According to Dictionary.com, the law states that “unless some tone indicator is used, it is impossible to tell the difference between an extreme view being sincerely espoused and an extreme view being satirized.”
Next up are a couple of words that we’ve all been hearing recently, both of which get their roots from the verb “whitewash.” “Greenwashing” is the “practice of promoting or affiliating a brand, campaign, mission, etc., with environmentalism as a ploy to divert attention from policies and activities that are in fact anti-environmentalist.”
And “sportswashing” is the “practice of rehabilitating the bad reputation of a person, company, nation, etc., or mitigating negative press coverage with a sports event (and) celebrating fans’ shared love of a game.” Words some countries try to LIV by.
In the term “crypto-fascism” the “crypto” has nothing to do with that form of money that I totally don’t understand. Rather it refers to something that’s hidden or secret. In other words, the noun “crypto-fascism” is simply “secret support for fascism.”
“Information pollution” is something we all struggle with on a daily basis. The noun is defined as “the introduction of falsehood, irrelevance, bias, and sensationalism into a source of information, resulting in a dilution or outright suppression of essential facts.
“Biohacking” is “biological experimentation, especially upon oneself, using technology, drugs, hormones, diet, etc., with the goal of enhancing or augmenting performance, health, mood, or the like.” (I was going to try that memory supplement that’s advertised ad nauseam on TV but I can’t remember its name.)
“Pessimize” is a fun verb. The opposite of “optimize,” it means “to make less good, efficient, fast, functional, etc., especially in the context of computers or information technology.” The word just happens to pair wonderfully with “bloatware,” which Dictionary.com says is “unwanted software that is preinstalled on a newly bought device, especially when it negatively impacts the device’s performance.
“Blursday,” reports the site, is “a day not easily distinguished from other days, or the phenomenon of days running together.” Apparently “Whoseday” and “Whensday” immediately precede “Blursday” in our “Groundhog Day” work weeks. (Are the other two weekdays “Munday” and “Frieday”?)
And finally, there’s “decision fatigue,” which is the cumulative mental exhaustion that comes from having to make the relentless small decisions we deal with throughout our day (which is probably one of the main reasons why we suffer through so many Blursdays and their immediate relatives).
Jim Witherell of Lewiston is a writer and lover of words whose work includes “L.L. Bean: The Man and His Company” and “Ed Muskie: Made in Maine.” He can be reached at jlwitherell19@gmail.com.
Loading....
Share this Article
Give this Article
You can share 5 more gift articles this month.
Anyone can access the link you share with no account required. Learn more.
Article link sent!
An error has occurred. Please try again.
Subscribe to gift this article
With a Press Herald subscription, you can gift 5 articles each month.
SUBSCRIBE TODAY
Already a subscriber? Sign in.
Invalid username/password.
Please check your email to confirm and complete your registration.
Use the form below to reset your password. When you've submitted your account email, we will send an email with a reset code.
« Previous
Mystery Photo for Sept. 17, 2023
Next »
Mark LaFlamme: Put on your galoshes and dungarees, boys, Hurricane Bruce Lee is a’comin’
Ok, this is a little bit bonkers: HeyGen's Video Translate tool will convert videos of people speaking into videos of them speaking one of several different languages (incl. English, Spanish, Hindi, and French) with matching mouth movements. Check out their brief demo of Marques Brownlee speaking Spanish & Tim Cook speaking Hindi or this video of a YouTuber trying it out:
The results are definitely in the category of "indistinguishable from magic".
Track outages and protect against spam, fraud, and abuse
Measure audience engagement and site statistics to understand how our services are used and enhance the quality of those services
If you choose to “Accept all,” we will also use cookies and data to
Develop and improve new services
Deliver and measure the effectiveness of ads
Show personalized content, depending on your settings
Show personalized ads, depending on your settings
If you choose to “Reject all,” we will not use cookies for these additional purposes.
Non-personalized content is influenced by things like the content you’re currently viewing, activity in your active Search session, and your location. Non-personalized ads are influenced by the content you’re currently viewing and your general location. Personalized content and ads can also include more relevant results, recommendations, and tailored ads based on past activity from this browser, like previous Google searches. We also use cookies and data to tailor the experience to be age-appropriate, if relevant.
Select “More options” to see additional information, including details about managing your privacy settings. You can also visit g.co/privacytools at any time.
Invalid username/password.
Please check your email to confirm and complete your registration.
Use the form below to reset your password. When you've submitted your account email, we will send an email with a reset code.