Most voted "dictionary" questions
A dictionary in computer science is a data structure that maps keys to such values that given a key of their corresponding value can be efficiently retrieved. Use this tag for this data structure and not for [dictionary-of-data] normally used with database or for [algorithms-to-dictionary] to manipulate traditional word dictionary
Learn more…184 questions
Sort by count of
-
0
votes1
answer343
viewsSplit dictionary in python
Good guys, even for help here from the forum, I got a function that creates sub-list from sub-lists according to the division by 10, is easier to understand with the code: def indexar(values): #…
-
0
votes2
answers43
viewsError in display of dictionary information
I am early in python and I am having a difficulty in the following code: class Gerador: def __init__(self, nome, potencia, capacidade_energia, capacidade_combustivel): self.__nome = nome…
-
0
votes2
answers28
viewsOrdering result
Good evening, I need help making a word sorting of that code. texto = '''amar e viver, Amar é sonhar, sonhar é viver, viver é curtir, curtir é amar''' def converte_texto(texto): pontuacao =…
-
0
votes1
answer243
viewsremove brackets from the values stored in a dictionary
When trying to use an excel spreadsheet as a data source for my DOCX-TEMPLATE, the dictionary I am generating is storing the values with brackets, and these and brackets are appearing in the final…
-
0
votes1
answer61
viewsConvert a sqlalchemy query to a dictionary - Python
I have this consultation made with SQLalchemy ORM, where table_schema contains an example of sqlalchemy column nq = session.query(Base.table_schema).filter(Base.tablename == 'stores').scalar() The…
-
0
votes2
answers60
viewsHow to add the rest of the division to the last Value of a dictionary?
I have the total of a purchase list and need to divide this total by the amount of emails which I have on my second list and return a dictionary. However, not all division is exact, so I need to add…
-
0
votes1
answer54
viewsPython - Dictionary - Writing and reading correctly
I’m having a problem reading the data from a dictionary I created to save data rebuilt by a function... The dictionary is written whenever the value of Amp and t is rebuilt in loop col. At each loop…
-
0
votes0
answers43
viewsConfusing data output in CSV
I am new in Python and am learning to analyze and write CSV files. I’m stuck in a problem I haven’t been able to solve for a few days: I’m trying to read a government database, also in CSV, take…
-
0
votes1
answer200
viewsCreate a contact list and separate it into two other lists
I have to create a list of contacts in Python, with name, age and phone number, and then I have to separate in 2 lists: a list only with contacts over 18 years old and another list only under 18…
-
0
votes2
answers59
viewsCreate Dataframe from lists with different sizes, keeping the data matching
I have lists of different lengths with data extracted from a PDF. Each value and code is part (is inside) of a respective note: cliente = ['12345','15432'] nota = ['21/0576750-3', '20/063859-1']…
-
0
votes1
answer8
viewsHow to add items to a dictionary without overwriting the previous item
Greetings!! With the code below, when instantiating an employee and then start the registration of hours worked informing the month and number of hours, inserting January: func01 =…
-
-1
votes1
answer216
viewsPython sort list of dictionaries by key and value in separate orders
How to sort a list of dictionaries for example: nomes = [{'nome': 'joao', 'sobrenome' 'alves'},{'nome': 'joao', 'sobrenome' 'silva'}] In alphabetical order the names In reverse order, surnames that…
-
-1
votes1
answer343
viewsDictionary for objects in Python
I wonder how I can assign a dictionary to a set of objects. For example, I have a 4x4 vector of 'neuron' objects': [[<__main__.Neuronio object at 0x1035644e0>, <__main__.Neuronio object at…
-
-1
votes1
answer115
viewsSplit subdictionaries in python
Good guys, I created a ICT, and I divided it using the function: listOfDicts = [{k:v for k,v in dictionary.items() if k%10==i} for i in range(10)] From that, I got 10 sublists: listOfDicts[0 a 9]…
-
-1
votes1
answer370
viewsUsing Values from a Dictionary Column to Create a New Column in a Dataframe
I am trying to extract country names from a string type column that I have to create a new column in my Dataframe with just country names. The format is below: ["[{'iso_3166_1': 'US', 'name':…
-
-1
votes1
answer79
viewsPython - update() failure to merge dictionaries
Hello I searched and found that dictionaryA.update(dictionaryB) is able to join the two dictionaries together. I tested and it actually works. But in the little exercise program below, it does not…
-
-1
votes1
answer98
viewsFunction returning only one value
I am making a program in Python and need to implement a function. The function receives as input two parameters: A dictionary containing as key the name of an employee and as value a list containing…
-
-1
votes1
answer66
viewsWorking with a python dictionary
I’m trying to resolve an issue in the URI, I’m going to put the description of the issue, and the link, whatever you prefer. Link: https://www.urionlinejudge.com.br/judge/pt/problems/view/1215 Andy…
-
-1
votes1
answer58
viewsHow do I alphabetize the Telephonic list that is separated between older and younger?
Before making a Phonebook containing name, phone and age, after capturing the data, I need to separate them into older and younger 18 years and print on the screen the result with all the data…
-
-1
votes1
answer73
viewsList Comprehension returning zero
Guys, I need your help. I have a code in python that I would like to return the amount of values that meet a criterion, but it is returning zero. The txt file contains data like this:…
-
-2
votes2
answers143
viewsDictionary doubt
How do I count dictionary elements? datum: I need to implement a phone account function, which receives a phonebook and returns the amount of registered phone numbers. If there are repeat phones…
-
-2
votes1
answer54
viewsGet the lowest value with the map in a Dict
I’m studying the function map() And I was wondering if there’s any way I could retrieve the least value from a dictionary within a list. The way I’m doing I’m only managing to change all values.…
-
-2
votes1
answer46
viewsIs it possible to create dictionaries using surreptitious ties?
I was wondering if I could create a dictionary using loops. But I don’t want to create a dictionary within a list [{ }]. example: from random import randint jog = dict() for n in range(1, 5):…
-
-2
votes1
answer92
viewsSum the total values of each key of the Python dictionaries
I have the following list of Python dictionaries : creches = [ { "nome": "Recanto do Sol", "cachorros": 12, "gatos": 4, "coelhos": 2, }, { "nome": "Lar dos bichos", "cachorros": 8, "gatos": 5,…
-
-2
votes4
answers87
viewsComparing dictionary values() with list values
I have the following dictionary and a list; from the dictionary I extracted the top 10 values. My question is this: I need to compare the keys of the respective values extracted from the dictMaior…
-
-2
votes1
answer56
viewsPerform function according to dictionary key
I want the user to choose an option and according to the chosen option the system performs a specific function. I wanted a more generic solution without a lot of if, elif and else. I thought of…
-
-2
votes1
answer1094
viewsRead Python Json file (beginner)
Good morning! I’m starting in python and I’m not able to read two specific fields in the generated json, with the following format: [ { "nomeArq": "arquivoA", "dataAnt": "28042020", "dataAtu":…
-
-2
votes1
answer147
viewsPython Dictionary - Most Common Word Count
good night. I am studying dictionaries, I have developed the following algorithm for word accounting in articles contained in TXT’s files and display of more frequent words, but I am not able to…
-
-2
votes1
answer54
viewsTrying to access a value inside a dictionary in Python, but I get an error when printing run the code
I was creating a dictionary playing with python Pokemon in pycharm Comunity, but when I went to perform the dictionary access, I was returned an error message in the code when trying to print one of…
-
-2
votes1
answer1591
viewsDicionario Python
Can anyone help me? I’m having a hard time doing this exercise. Consider the following data set: Name + (N1, N2, N3, N4). Name represents the name of a student and should be used as key. N1, N2, N3,…
-
-3
votes1
answer147
viewsPython: How to get a dictionary key based on the value?
I have a dictionary in table format={"t":148} I can return 148 by doing table["t"], right? How can I make to return "t" based on the 148? When I try to print table[148] ends up returning "None",…
-
-3
votes1
answer71
viewsSum values of a string by assigning values to letters (Python)
Goal: Assign values to a string based on a dictionary with keys and values Example: I have a string in this format: str = 'ABCD' and a dictionary in this. dic = {'A' : 71, 'B' : 103, 'C' : 115, 'D'…
-
-3
votes1
answer136
viewsFunction within a Python dictionary
I am trying to perform an exercise where when creating a log file dictionary whose key is returned a random number between 100 and 9999 as enrollment as follows from datetime import date, time,…
-
-3
votes1
answer23
viewsForce the user to answer a valid alternative in a multiple choice Python question system
The code below works well, but I would like it to ask the specified question again if the user does not type one of the three available alternatives. perguntas = { 'Pergunta 1': { 'pergunta':…