All Questions
1,825 questions
-1
votes
1
answer
69
views
Representing the maze in the Dictionary in Python
I am a new computer science student, and now we know the Python language. It is beautiful, but I have many problems with it. Sorry, I can solve this question.
enter image description here
I tried to ...
1
vote
2
answers
43
views
Expanding the Dictionary item from datafame column
I have pandas dataframe with a column
I have a dataframe with a column having the value like below
df['dbpedia_entry']
{'dbpedia_entity': ['c'],'dbpedia_id': ['f'],'dbpedia_label': ['k'],'...
1
vote
1
answer
48
views
Why is my code not displaying firstNotRepeatingCharacter in the string, in Python?
So, I am solving this code signal problem and it's problem statement is as follows
Given a string s consisting of small English letters, find and return the first instance of a non-repeating ...
1
vote
0
answers
87
views
What is the meaning of nums[complement] in the following line of code return [nums_dict[complement],i] in Python?
So, I am solving a problem of Two sum which has a following problem statement : **Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to ...
0
votes
1
answer
42
views
map list based on dict internal values
I have a list like:
[{'sample': {'sample_context': {'board': u'9', 'encoder': u'1'}, 18421: u'1191'}}, {'sample': {'sample_context': {'board': u'5', 'encoder': u'1'}, 18422: u'2251'}}, {'sample': {'...
-2
votes
2
answers
101
views
How to decrypt or convert Python Dictionary of lists to normal dictionary
Very new to python and literally struggling to get this fixed. I have dictionary like below from json file. I believe this is being called as Dictionary of lists.
MyDict = [{Key:[1,2,3,4]}, {Summary:[...
1
vote
2
answers
52
views
Get the list of names which satisfy the condition in dictionary from given list
I have a dictionary in which there are three conditions startwith, contains and endwith given below,
dict1 = {'startwith':"Raja, Bina", 'contains':"Tata", "endwith":"...
-4
votes
2
answers
191
views
what is "count[character] = count[character] + 1" doing in this program to count letters in a sentence
The line of code below is meant to count the number of individual letters in the sentence assigned to the variable "message".
message = 'It was a bright cold day in April, and the clocks ...
0
votes
1
answer
37
views
Python Version Creates Different Dictionaries [duplicate]
I have a script which needs to be compatible with both Python 2 and 3. The code utilizes a dictionary with is generated using the following line of code:
x = {2**x-1: 1-1/8*x if x>0 else -1 for x ...
0
votes
1
answer
181
views
Convert one column csv into Dictionary with same key:value pair in python 2.7 (using import csv)
I have one CSV file as sample.csv which contains
ABC
XYZ
LMN
...
And from this file, I have to make a dictionary like below
Dict = {'ABC':'ABC','XYZ':'XYZ','LMN':'LMN',...}
using import csv
0
votes
1
answer
60
views
Parsing data from file of 3 columns to store data in dictionary with structure dict[key1][key2]
I am trying to solve the task:
Read data from the "Region", "Range" and "Population" columns.
Region Range Population
Region1 23 1299
Region1 34 ...
0
votes
1
answer
64
views
How to sort python dict based on multiple dict keys?
For the following data, I am looking to sort the data first by the "date" property, and then by the "name" property.
Input:
results = {
"a":{
"date":&...
0
votes
5
answers
95
views
How can I create a pro-rated salary scale dictionary using a for loop?
somewhat new to Python here and wondering what the best way to accomplish this task would be. I am trying to create a dictionary that represents a pro-rated salary scale for a certain amount of days.
...
-2
votes
4
answers
92
views
how to sum the quantities of dictionary items if the items are same
Shopping_list= [
{"title":"cheese","quantity":50,"unit":"gm"},
{"title":"cheese","quantity":40,"unit":"gm&...
-1
votes
3
answers
1k
views
Removing a key in a list of dictionary with if value condition in python
Here's my sample data, I want to remove the keys with "N/A" values using python.
Data = [
{
"Area": "Los Angeles",
"Idle": "N/A",
"...
-2
votes
3
answers
1k
views
How to append Dictionary keys null values in a list?
I have a dictionary that has multiple keys and each key has multiple values in list format, if the keys have a Null value then the key should be appended to a list.
here is my dictionary:
{'XSTY':['21....
-3
votes
1
answer
91
views
calling functions from python dictionary
How to call multiple functions based on the input values. We can implement this with dictionary without using if-else by below:
def fun1(a, b, c) :
....
def fun2() :
....
def fun3() :
.....
dict{1 :...
0
votes
2
answers
256
views
Removing duplicates from a list in a nested dictionary using setdefault()
I'm creating a nested dictionary where the inner dictionaries value part will be a list that should maintain order. I can achieve a solution but I would like to do this when I first create the ...
1
vote
2
answers
75
views
Assign value from the second dictionary whose key is the value of the 1st dictionary
I have two dictionaries:
# ModName : Details for the Modules Present and Intent information
{'ClickUrl': ['HTTP'],
'AngryUser': ['HATE'],
'HelloGoodBye': ['HELLO'],
'Social': ['TEAM_WELLNESS', '...
0
votes
0
answers
15
views
get nested item from request.json python [duplicate]
I have a piece of code like below
url = "https://blockchain.info/balance?active="+pub
r = requests.get(url)
print(r.json())
above code prints below output
{u'0jhke23k23k4j4k3434kk54l54': {u'...
0
votes
5
answers
430
views
Dictionary keyError on dynamic value
I have a code in my python file that is given below.
data_to_parse = """
Repo: 2msdsdodule-losdsdader
Path: 2modsdsule-loasdsdder
Components: 2sssss-sdsds sds-sdsd-test ...
0
votes
0
answers
183
views
Create a single dictionary of nested dictionaries from *multiple* dot notation strings [duplicate]
I have a number of dot notation strings and their values that I want to use to create a dictionary of dictionaries, but I'm stuck...
For example, I have these strings:
tagPaths = []
tagPaths.append(&...
0
votes
1
answer
92
views
Python dictionary - Remove dictionary from list of dictionaries
I have this dictionary:
my_dict = {
"camel_configuration": "rEIP.cccf",
"test_environments": [
{
"Branch Coverage": "78/78(100%)",
...
-2
votes
1
answer
369
views
check unreachable code in most simple way in python [closed]
I have a python code with is detect any errors in another python code saved in txt file, i did that i can detect magic numbers and more than 3 parameters in the function, and now i have to check un ...
0
votes
2
answers
283
views
storing all function body from txt file in dictionary in python
I'm trying to do code analyzer app and i have a txt file that contains a python code and my goal now is to save all functions in this txt file in dictionary in the class, but i don't have any idea how ...
1
vote
2
answers
147
views
Create multiple dictionaries in an efficient way
I have to create more than 10 dictionaries. Is there a more efficient way to create multiple dictionaries using Python's built-in libraries as described below:
dict1_1= {
"value":100,...
0
votes
3
answers
535
views
Dictionary - how to add condition for specific value of key and value?
my_dict = {
"camel": "ok",
"test_environments": [
{
"Branch Coverage": "-",
"ASIL": "ASIL-D&...
1
vote
2
answers
296
views
AttributeError: 'unicode' object has no attribute 'pop' - Python list of dictionaries
I have
my_dict = {
"test_environments": [
{
"Branch Coverage": "97/97(100%)",
"project" : 'ok'
...
0
votes
4
answers
179
views
Python - split value to two integers
What is the most optimal way to split this key/value of dictionary:
test_status: "2200/2204(99%)"
so that I get two keys whose values are integers:
test_status_excpected: 2204
...
0
votes
1
answer
55
views
Python list of dictionaries - access keys
I need to change name of the keys in dictionary using item.replace(" ", "_").lower()
How could I access these keys?
{
"environment": [
{
"Branch ...
0
votes
1
answer
32
views
Python dictionary - more optimal
How could I make this code more optimal, not to have repetition?
for item in my_dict["environment"]:
item.update({"service": service})
item.update({"project_name":...
1
vote
2
answers
952
views
Mapping a dictionary to NAN rows of a column in Panda
Here as shown below is a data frame , where in a column col2 many nan's are there , i want to fill that only nan value the col1 as key from dictionary dict_map and map those value in col2.
...
1
vote
1
answer
631
views
'map' object is not subscriptable,How to extract a part of map
66 test_indexes = set(random.sample(indexes, len(indexes)//2)) # removing 50% edges from test data
67 train_indexes = set(indexes).difference(test_indexes)
---> 68 ...
0
votes
1
answer
935
views
How can I recreate Python 2's dictionary "ordering" in Python 3?
I am trying to migrate a Python 2 dictionary to Python 3.
The dict ordering behaviour has of course changed:
Python 2: Unordered - but in practice appears to be deterministic/consistent between ...
0
votes
1
answer
79
views
How to read two files into a dict and print specific values
So, I am learning python and have these fun assignments
I have two files rating_strikers1.txt and rating_strikers2.txt where they have rated some football strikers from 1 to 99.
The textfile ...
0
votes
0
answers
26
views
Merging two Dictionaries with togrther [duplicate]
I try to merge two dictionaries with together with out update() method. What is your offer to use with new ways?
-1
votes
2
answers
70
views
python: lookup in a list of dictionaries
I have a dictionary where the value is a list of dictionaries:
{ 'client1':
[
{ 'id': 123, 'name': 'test1', 'number': 777 },
{ 'id': 321, 'name': 'test2', 'number': 888 },
{ 'id': ...
-2
votes
2
answers
266
views
How to add new keys and value of each of them in python with list? [closed]
I have a dictionary and a list.
I want to add a new key to the dictionary so that the value of each of them is equal to one of the array elements. I have explained more about this in the example below
...
0
votes
2
answers
41
views
I can't let the data to remain in the dictionary, it keeps updating instead
I got myself a python book. Currently, in the book, I am learning about dictionaries. The book gave me an exercise about dictionaries. This is the question.
"Create a program that pairs student's ...
1
vote
2
answers
96
views
How to speed up the search of the closest geopoint?
Currently, I use the following code to find the closest given geopoint -
def get_closest_stops(lat, lng, data=db.STOPS):
def distance(lat1, lon1, lat2, lon2):
p = 0.017453292519943295
...
2
votes
4
answers
1k
views
Printing dictionary without brackets
I'm trying to write a script for an exercise that allows me to sort out the characters on a string and count the highest recurring characters but I can't seem to print out the results in a form of a ...
-1
votes
2
answers
161
views
Convert an unstructured list of dictionary to structured list of dictionary using python
I have below content as output.
['{end_date=2021-09-16 06:00:00, number=CHG1757, requested_by=Tom, cmdb_ci=Checkout, start_date=2021-09-16 03:00:00}',
'{end_date=2021-09-16 09:00:00, number=...
-1
votes
1
answer
69
views
How to sort all the keys, sub-keys, sub-sub-keys, etc of a dictionary at once?
Is there a way to sort all the keys, sub-keys, sub-sub-keys, etc. of a python dictionary at once?
Let's suppose I have the dictionary
dict_1 = {
"key9":"value9",
...
0
votes
2
answers
22
views
Add values to an existing list inside a dictionary based on matching items from another dictionary
I am struggling to merge values from a second dictionary to the initial one.
The initial dictionary is:
dictionary1 = {u'user1': [[u'N/A', u'N/A', u'N/A', u'N/A', u'N/A', u'N/A', u'N/A']],
...
-2
votes
2
answers
65
views
I have these dictionaries. What command should I put to print the "d" key from the second one? There is a trick
So, the first requirement was to print the key 'a' from d1, which was very simple.
The second one was to get the key 'c' from d1, which doesn't exist. And if doesn't exist return
the 0. This one I ...
-1
votes
4
answers
270
views
How do i change the value of a specific item in a list with many items?
Im kind of new to python and need some help.
How do i change the value of a specific item, (in this instance :"unit price for one product" in a list/dictionary with many items/products ?
...
0
votes
0
answers
44
views
how to merge more than 2 dictionaries in python 2.7 [duplicate]
Trying to merge two or more dictionaries in python 2.7, However
**kwargs is not supported in python 2.7 it gives error like-Python version 2.7 does not support starred expressions in dicts .
is there ...
0
votes
3
answers
58
views
Iterate through a Python Dictionary and delete a particular element if matches a specific string
I have a dictionary like-
mydict = {
'users': [
{
'userid': 'u1234',
'name': 'user1'
},
{
'userid': 'u0007',
'name': 'user2'
}
]
}
I want a functionality ...
-1
votes
1
answer
52
views
Convert list of string dictionary to another dictionary using python 2.7 and print in tabular format
Here's the data that I have:
['{"end_date":"2021-07-15 09:00:00","number":"CHG81923","requested_by":"Dan","cmdb_ci":"LR ...
-1
votes
2
answers
178
views
dictionary in python sum prices with 2 inputs
I have 2 inputs:
# The key is the available dates and the value is the price
a = {"g": 109192, "e": 116374, "o": 183368, "s": 162719}
# The dates that the user ...