We’re rewarding the question askers & reputations are being recalculated! Read more.

All Questions

Tagged with
Filter by
Sorted by
Tagged with
-1
votes
4answers
41 views

How to call a dict value with the value given as an input variable in python

most_used_languages = { 1: "Mandarin Chinese", 2: "English", 3: "Hindustani", 4: "Spanish", 5: "Arabic", 6: "Malay", 7: "Russian", 8: "Bengali", 9: "Portuguese", ...
2
votes
3answers
25 views

Dict comprehension from split str

I'm trying to make a dict out this str: a='ALLELEID=677660;CLNDISDB=MedGen:C0162671,OMIM:540000,Orphanet:ORPHA550,SNOMED_CT:39925003;CLNDN=Juvenile_myopathy,_encephalopathy,...
-2
votes
1answer
29 views

Seperating the numbers from strings to do the maths and return the string with the results [on hold]

I have some files like this. They are some receipts of restaurants. --------------------------- CompanyID: 000000000000 ProductName: quantity costPerPizza sumCost --------------------------- For ...
-1
votes
2answers
29 views

How to get the maximum value in a list of dictionaries in python

I have a list of dictionary as follows, with different keys and values. list1 = [{'a': 15554}, {'v': 453}, {'a': 441742}, {'vb': 7785}, {'vv': 4275}, {'g': 7822}, {'l': 47537}, {'fg': ...
-1
votes
6answers
38 views

function saving words as keys [on hold]

I'm trying write a function that reads the words contained in the .txt file and writes them as keys in the dictionary. The value can be any. The program should allow me to use the in operator to check ...
0
votes
2answers
33 views

Example program from Automate the Boring Stuff not working as described

I've been poking about the internet and not seeing this anywhere so it must be something I've done but I'm not sure what. The book Automate the Boring Stuff with Python uses the following code to ...
0
votes
0answers
57 views

All about python dictionary

I am working with python dictionaries to save some numbers iteratively. I am facing multifarious problems dealing with dictionaries. Dictionary 1st issue: In one dict I am saving integer iterations ...
0
votes
2answers
40 views

Create a dictionary using the row number in a csv file [Python]

I have a CSV file containing survey data on 60 participants. The first column is the participant's number, and for each number corresponds all the data collected from that participants. It looks ...
0
votes
1answer
26 views

Why do I get a TypeError in this Python program? [duplicate]

# I'm trying to make a Zipf's Law observation using a dictionary that stores every word, and a counter for it. I will later sort this from ascending to descending to prove Zipf's Law in a particular ...
0
votes
4answers
47 views

Counting the elements inside a list of list

I have a list of lists as follows [ ['DDX11L1', 'lincRNA', 'chr1', 11869, 14409], ['WASH7P', 'lincRNA', 'chr1', 14404, 29570], ['MIR1302-2HG', 'lincRNA', 'chr1', 29554, 31109], ['FAM138A', '...
0
votes
1answer
16 views

Getting the latest value of duplicate keys in list of dictionaries

I have a list of dictionaries like this UNFILTERED LIST OF DICTIONARIES: [{'team': 'green', 'user': 'bob'}, {'play': '${bla/bla}', 'mentor': 'alice', 'team': 'blue'}, {'team': 'yellow'}] i need to ...
-2
votes
0answers
26 views

Can a dictionary value reference to a file? if yes how can we achieve it? [on hold]

I am actually trying to make a file system by a nested dictionary such that the first dictionary contains the directory id and directory name and the directory id further points to another dictionary(...
1
vote
3answers
33 views

Python: filter lines based on field match from another file

I have generated a list with my other python code, which looks like this. there are lines separated by commas and they are in single quotes. I am trying hard to filter the lines based on D: column ...
0
votes
4answers
35 views

Search keys in the dictionary and return both key and value [on hold]

I have this dictionary like {'Mike':'98','Tom':'57'}. How could I do search based on names which is the key in this case and return both key and value? I have roughly heard about create a turple of ...
-2
votes
3answers
38 views

How to get dict from json one line dict

I have a json file with a dict and I want to get that dict. I tried json.load(), but there comes this error message: 'json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)' I saw ...
-1
votes
0answers
19 views

Find the hair color where the confidence is max in list of dictionary [duplicate]

I want to find the hair color in the dictionary whose confidence is maximum amoung all dictionary python. myList = [ { "color": "black", "confidence": 0.98 }, { ...
0
votes
2answers
35 views

Convert list of 2D lists to Dictionary

I am trying to convert a list of lists to a dictionary. Initial list of the form: test = [['A', 27], ['B', 33], ['C', 42], ['D']] Final dictionary should be of the form: dictionary = {'A': 27, 'B':...
2
votes
2answers
31 views

Convert all keys inside [dict] to dict in python

Any elegant way to convert all keys inside dict list to dict? Like this: aa = [ {"option": "-c","params":4}, {"option": "-t", "params": 8}, {"option": "name", "params": "bb"} ] bb = ...
-2
votes
1answer
20 views

Merging 2 dictionaries by keys without overwriting

Suppose I have 2 dictionaries: ss = {'1':{'tier 1': {'valid_detailed': 66, 'valid_approx': 68, 'valid_unmapped': 56, 'valid_total': 288}}} tt = {'1':{'tier 2': {'valid_detailed': 44, 'valid_approx': ...
2
votes
3answers
37 views

How can I count how many keys have a certain value in a dictionary?

I have a dictionary looking something like this: d = {'f1': ['a','a','b','c'], 'f2': ['b','c','d'], 'f3': ['a','c','d']} I want to get information about how many keys have a certain value. ...
0
votes
0answers
17 views

Iterate through JSON object returned as a list with nested dictionary?

I have very limited experience with JSON, but I have a working function that returns a JSON list with three values, the last value being a nested dictionary. I would like to manipulate the list by ...
0
votes
3answers
33 views

Creating a nested dictionary from tuples that counts the number of occurrences of a tuple item

I have to sort through a list of tuples and create a dictionary with the first item in the tuple as a key and nested dictionaries which would have the key as the second item and the number of ...
0
votes
0answers
29 views

list to dictionary mapping

am trying to put excel sheet2 data into a list(list_sheet2). Then am again trying to put excel sheet1 data into a dictionary(dict_obj). After that am trying to take list_sheet2's key data and dict_obj'...
1
vote
3answers
53 views

How to create sub-dictionaries without overwriting each entry?

east = {"George Street": "52.1382238, -0.4496112", "Barnstable Road": "52.143864, -0.4474769", "Newnham Avenue": "52.1367876, -0.4448371"} mainzone = {"Anglia Cars": "52.138622, -0....
0
votes
0answers
21 views

How to update a dictionary using sockets (Python)

I am working on a multiplayer game using sockets. I am sending the dictionary fine but for some reason client 1(the first client I run) only has index 0 in the dictionary, client 2 has both index 0 ...
0
votes
1answer
20 views

scrape values from nested json dicts

I have data like the example below. It has dict, which has keys that are lists. Those lists also contain dicts. I want to create a list like the desired output below, where I've scraped the "Id" ...
0
votes
3answers
27 views

Converting huge sets of data (dictionary) to tables

enter image description hereI want to convert the data to a tabular format. Can you please help me with this. I have shown below the two rows of the extracted data from json files. I need to convert ...
2
votes
4answers
98 views

Recursively remove None value or key from nested dict

Question: How I can iterate over a dictionary and remove None key or value in it? Here is what I had tried: Code: import copy def _ignore(data): copied_data = copy.deepcopy(data) print('-...
-1
votes
2answers
64 views

Break is not activated inside a for loop in Python [on hold]

I want to print the first 10 key-value pairs from the dictionary word_index and I wrote this code: for key, value in enumerate(word_index): count = 0 if count <10: print(f'key {key}...
0
votes
1answer
28 views

picking up one key from multiple keys having same set of values

I have dictionary with following pattern input_dict_data = {'how to access outlook on open network': {'intent': 'access_email_from home'},'how to access evpn': {'intent': 'access_email_from home'},'...
-1
votes
1answer
19 views

Find min value based on Some conditions in python list?

I have a list value. I want to find a min value of Rank based on the same category values. [{'PlayerName': 'aaaa', 'Category': 'MVP', 'Rank': 1}, {'PlayerName': ' bbbb', 'Category': 'MVP', 'Rank': ...
0
votes
1answer
47 views

Alternatives to for loops traversing 3 lists of dicts

So I've seen a few posts which I've tried to look at but my use case is a bit different. I have 3 lists which have multiple dicts in them and to get information from them I sometimes have to go ...
0
votes
0answers
14 views

Initialise a python dictionary with a string?

I'm trying to understand one of the most elegant solutions to a Leetcode problem (Remove Invalid Parentheses) provided by the legendary Leetcode ace StefanPochmann: https://leetcode.com/problems/...
0
votes
2answers
25 views

Calculating average of specific dict key values Python 3.7.4

I am trying to calculate the overall average for my grades dict. Subject level and subject code does not matter.These are my dicts and lists. grades = {'INFO100' : 'C','INFO102' : 'B', \ '...
2
votes
2answers
33 views

How to retrieve max key and corresponding value from the tuple in the dictionary based on the first argument of the tuple

For example, if the given dictionary is as following: dic = {('K1', 'S1'): 4.999997655759467, ('k1', 'K2'): 6.1999036349232375, ('K1', 'K4'): 7.999999999999876, ('K2', 'K1'): ...
2
votes
1answer
28 views

Iterating on dictionary throws TypeError: list indices must be integers or slices, not tuple

I am trying to iterate over my dictionary with the following code: num_detections = int(detection['num_detections']) output_dict = {key:value[0, :num_detections].numpy() for key,...
1
vote
4answers
60 views

How to create a dictionary from a list of lists in python?

Given a list of lists, how can I create a dictionary where the keys are all the items in the list (one copy), and the values are the number of times they are the first item in the list? Given: [['...
-1
votes
2answers
17 views

How to return a dictionary from a list where the keys are items in the list and the values are the number of occurrences in that list in python? [duplicate]

Create dictionary from a list, where items of list become the keys and values become the number of times they are in the list.
0
votes
1answer
41 views

How do I create a dictionary dynamically?

Let's say I have a function that returns a numeric value called get_miles_sum_by_region(). It takes several parameters (region, tier, study_type): region = 1 reg_tier1_approx = ...
0
votes
1answer
55 views

Cant Access Data in List of Dictionaries

I'm trying to access some data within nested ordered dictionaries. This dictionary was created by using the XMLTODICT module. Obviously I would like to create my own dictionaries but this one is out ...
0
votes
3answers
24 views

Recursive function for nested dictionary returns None however prints the expected data in function [duplicate]

I have a JSON with many nested dictionaries and list that I need to modify and when I want to find the data it returns no result. However it prints the expected values before the return. Below a ...
1
vote
1answer
24 views

Python - Map with Split Option output Difference

I'm a newbie to python just trying to understand why the output is like this. 1) strr=['asdfasdf','asdf','sdf','sdf'] stak=map(lambda l:l.split(','),strr) print(stak) When i execute the first ...
0
votes
1answer
21 views

How to compare lists ranges where a repeated index will cause a difference in length in Python 3x

I am trying to compare two lists, where one is a list of inputted guesses, and the other is a randomly selected word from a .txt file. It works until the random word contains more than one instance of ...
0
votes
1answer
29 views

How to take more than 1 element off a list and keep it as a tuple, and then assign the tuple as the key of a dictionary?

Say there is a list of strings. I want to take n number of strings from the list and store it as a tuple. Then I would like to make a dictionary where the recently created tuple is the key. What's the ...
1
vote
0answers
47 views

How to read required key, values from json response and store it in json format using robot framework?

I am trying to read the required key and values from JSON Response and store it in JSON file. I have a sample simplified json format as below: ${API_Output}= { "data": { "resources": { "edges": [ { ...
0
votes
0answers
36 views

How to update a dictionary every N seconds and return the difference?

I am making a GET request to an API that gives me a dictionary of songs. My goal is too keep up with the new releases by making this same GET request every N seconds and then printing the difference ...
0
votes
2answers
20 views

Converting xml data into list of dictionaries to load into tables

I have written a code to convert xml data into list of dictionaries and load into tables. Input file data: <report> <report_header type='comp1' title='industry' year='2019' /> ...
2
votes
5answers
49 views

How to append multiple values to a key using a function in Python?

I want to declare a dictName variable. Then I'd like to implement a function, that adds values to keys of dictName. and I want these keys to be added in the function aswell. So basically something ...
0
votes
1answer
40 views

How to combine dictionaries in a list into one dictionary with values of same keys added?

I am trying to convert a list that contains dictionaries to one dictionary where the values for common keys are added. Use this list as an example: list = [{'Apple': 3, 'Orange': 2}, {'Apple': 1, '...
1
vote
1answer
26 views

Summing a list of dict with different keys

I have a list of dict, with different keys and values, I want to aggregate on the value, the structure of the dict is as follows: Structure: for dic in doc_complete_views: for val in dic.values()...