Skip to content
Advertisement

Tag: dictionary

How can I write with a translator’s dictionary?

This is how my program is structured: There is an n in the first line of the input that indicates the number of words in the translation dictionary. Each of the next n lines contains four words, the second to fourth words being the translation of the first word. Each word is translated into three different languages. The second word

Build a dictionary from .txt files analysis

I have a basic program that can count the number of words in a given text file. I am trying to turn this into a program that can take in several different .txt files, with an arbitrary amount of keywords within those file analyzed, and output a dictionary within a list of the results (or similar object). The output I

How allocation of memory for `dict` in Python works?

I was playing around with Dictionaries and found this. Output: The size of Dictionary length 7 and 10 is the same that is 196 but for length 11, it’s 344. Why are they same? Why does the size rise up with length 11? How does dictionary size work in Python? Answer When you create an empty dictionary, it preallocates the

How can i make this Python code less repetitive?

I was looking for the way to call different functions based on variable and i came up with this dictionary mapping. I wonder if there is a way to somehow improve it and make it less repetitive? Answer You can use getattr to get the property name from a string:

Advertisement