All Questions
69 questions
1
vote
2
answers
54
views
Awk print a value in a column that corresponds to key values
I want to add a column to a file depending on a key value.
I have infile_chr"N".txt (where N is a number from 1 to 22) and I need a single output file (outfile.txt) in which the first column ...
0
votes
3
answers
54
views
Trying to check if key present in array of objects inside of an array of objects
I need a way to return true or false if in changeFields array "printLogs" key is present or not. The object is shown below. I have tried looping but somehow cant get my head to wrap around ...
0
votes
1
answer
27
views
Converting a list of dictionaries into a list of tuples
I am a rank beginner, so appreciate any help. I have a list of dictionaries:
lst = [{'name': 'John', 'gender': 'Male', 'marks': [20,30,40]},
{'name': 'Lynn', 'gender': 'Female', 'marks': [20,...
0
votes
1
answer
34
views
Add values for keys that contains similar string in python
I have dict as
values={'P-ETH-900':Decimal(122),'P-ETH-700':Decimal(455),'P-BTC-900':Decimal(12),'P-BTC-700':Decimal(55)}
I want to add the decimals that has condition like
eth=Decimal(0)
for i,j in ...
0
votes
1
answer
48
views
Angular iterate Object with name and values
I need your help please.
I have a interface with 30 properties. I call a Rest API, written in C#, and get a DataTable back with the results. Now i can convert this result to my interface.
My interface ...
1
vote
3
answers
128
views
python - extract value from list of dictionary
I need to display book name and calculate average weight of book if the book price is more than 800.
here is my current code, appreciate any help. thank you so much in advance!
def calcWeight():
for ...
-1
votes
1
answer
148
views
Dictionary values deleted after each iteration
def buildCodeDict():
auto_dict = {"A": "Alpha", "B": "Bravo", "C": "Charlie", "D": "Delta", "E": "...
2
votes
5
answers
130
views
Printing dictionary pair and next iteration's pair on one line in columns
I have a long list of 100+ unique (names don't repeat) key/value pairs which I'd like to print consolidated into two equal width columns.
How do I get the next iteration's key/value? (i.e. How do I ...
0
votes
2
answers
333
views
Angular keyvalue -> How to iterate again when key is array?
How to iterate again through my object key when it is an array?
Here my HTML:
<tbody>
<tr *ngFor="let duplicate of duplicates | keyvalue; let i = index ">
<th scope=&...
0
votes
2
answers
50
views
Comparing key-value from two dictionaries Python
I have this
a = [{'name': 'John', 'supporterId': 1}, {'name': 'Paul', 'supporterId': 2}]
b = [{'dependent': 'Erick','supporterId': 2, 'email': '[email protected]'}, {'dependent': 'Anna', 'supporterId': ...
2
votes
3
answers
63
views
Comparing key-value pairs in Python
I have something like this
a = [{'name': 'John', 'supporterId': 1}, {'name': 'Paul', 'supporterId': 2}]
b = [{'dependent': 'Erick','supporterId': 2}, {'dependent': 'Anna', 'supporterId': 2}, {'...
1
vote
1
answer
389
views
Python compare list to dictionary with multiple values and return matches
If I this list:
list1 = ['a long way home she said', 'amazing grace for me', 'shes super cool']
I want to compare each item in list 1 to the values in dict1 below:
dict1 = {
'Formula1': ('a long way ...
0
votes
2
answers
2k
views
how to convert from list of lists to a dictionary
Hi :) I have this table and I need to convert it into a dictionary where the firsl line are the keys and then each value from the rest of the tables will be values but iterating through them each at ...
1
vote
1
answer
1k
views
Change a table value with a loop in lua
I'm trying to change a value inside a table but I can't.
This is my code:
table = {{x=2}, {y=3}, {z=2}}
function printTabValue(tab, index)
for k, v in pairs(tab[index]) do
print(k, v)
...
0
votes
0
answers
348
views
Loop through FormCollection with index and key name to get value
I am trying to loop through a FormCollection where I want to specify the index and key of the formcollection but am not having luck.
FormCollection Keys Example
form[0][keyA]
form[0][keyB]
form[0][...
0
votes
1
answer
493
views
How to update nested dynamic object javascript nodejs
I'm trying to dynamically update values inside a nested object like this :
mainObj = {
'Test 1': {
Nested1: 'value 1',
Nested2: 'value 2',
Nested3: 'value 3',
Nested4: 'value 4',
...
0
votes
1
answer
69
views
How do I determine if a pair of values in a hashtable answers a condition?
I am trying to enter pairs of values (i,j) in an array to determine how many of those pairs respect the following condition: 1 <= i < j <= length of the array. The output is rarely the right ...
3
votes
3
answers
2k
views
Best way to find nested property by name in object
I have an object (dataLayer), which can increase and decrease in length, depending on how many pages you've visited.
I want to:
Loop through the objective and look for the property name "...
0
votes
5
answers
91
views
What's the best way i can iterate over a hash in this manner?
so i have this hash and i want to write a program that, given a person’s score can tell them:
a) whether or not they’re allergic to a given item
b) the full list of allergies.
allergies = {
1 =...
0
votes
1
answer
204
views
JSON loop through key value pairs to set another key value
I'm very new to scripting and JSON and I'm trying to loop through some key pairs in an object (shown below) to accomplish, "if the value in 3[x].4 = 'BBB', then return the value in 3[x].1"
...
0
votes
1
answer
74
views
Iterate through nested JSON list and add one value to a list
I have a bunch of JSON data that I need to extract one value from. Unfortunately it's rather deeply nested and I can't figure out a way to pull the specific values out that I need. Here's a sample of ...
0
votes
0
answers
467
views
C# Get key/name from JSON children
I am recieving this JSON response from an API:
{
"type": "link",
"title": "One or more validation errors occurred.",
"status": 400,
"...
-1
votes
2
answers
48
views
Python: How to loop through a dictionary mutiple times?
I want to create a code that has a dictionary that can print out different types of outcomes. I have two dictionaries. One of them have different sets of outcomes and the other dictionary values are ...
1
vote
2
answers
2k
views
Google Script - iterate over JSON object key value pairs
My iteration over the JSON object doesn't work as expected.
What's wrong?
function handleResponse(e) {
var jsonObj = JSON.parse(e.postData.contents);
console.log("Note=" + jsonObj['Note']...
2
votes
1
answer
1k
views
Taking Key Value pairs from a List<Object> and adding to a new List<Object>
I have a List<Object> that contains Objects with Key Value pairs.
I want to loop through and if a Key value contains a certain Value. I want to pull that object and create a new List<Object&...
-2
votes
1
answer
250
views
How to compare map values in loop with JavaScript? [closed]
Say I have
const food = new Map();
const max = 0;
food.set(hotdogs, 2);
food.set(pizza, 8);
I'd like to compare the values in my map to other values in my map, (for example: which is larger, 8 or 2?...
2
votes
4
answers
412
views
How to find Common Keys in key value Pair which are Less than the Specified Threshold
I have a dictonary with key value pair where I want to set threshold as less than 50% for value which basically means in any of the key value pair where value pair has value less than 50% of all ...
-2
votes
1
answer
481
views
How to print full NBA teams when you only have the abbreviated team names? [duplicate]
I am new to coding and having trouble solving an issue. I found some code online regarding this subject but it did not work how I would like it to.
Let's say I have 3 abbreviated NBA teams in a list:...
1
vote
1
answer
60
views
Ruby - Tell user what stage of the day and season of the year (Use Hash)
I have a question for the following challenge.
1) Tell the user what season of the year it is. Condition is I need to use hash.
What I want to to loop seasons and find an element that is equivalent ...
0
votes
2
answers
911
views
How to jump from key-value pairs in a dictionary to create a list of cycle
In my homework, a cycle is defined as a set of keys that jump from key -> value -> key that returns to its original starting value. For instance:
d1 = {1:6, 3:1, 6:3}
cycles = [[1, 6, 3]]
because 1:...
0
votes
1
answer
2k
views
Extract value from key-value pair of dictionary
I have a CSV file with column name (in first row) and values (rest of the row). I wanted to create variables to store these values for every row in a loop. So I started off by creating a dictionary ...
1
vote
5
answers
65
views
how to iterate over a dictionary from value in an array and store in a new dictionary
I have an array(Arr[]), for each item in the array i would like for it to go through a dictionary(specs{}) and calculate the corresponding values and store them in a new dictionary but on sure how to ...
0
votes
2
answers
50
views
How can I update a dictionary so that if key 'a' has a value of 'c' than the key of 'c' appends the value 'a'?
If key 'a' has a value of 'c' then the key of 'c' should append 'a'. Please note that that the values associated with key 'a' are not included in the append.
I cant seem to figure out how to ...
-2
votes
2
answers
1k
views
How to iterate over list of values of one key in a dictionary
i want to compare the values (a tuple of floats and a boolean variable) of matching keys of 2 different dictionaries to print out possible differences. The keys are IDs and I want to make sure to have ...
0
votes
6
answers
2k
views
How to iterate over a string and for each letter, if it is in a dictionary (key), add values to a new list?
What would I write to iterate over a string and for each letter, if that letter is in a given dictionary (as a key), then add that key's value to an empty list?
For example the string 'cat', I want ...
4
votes
5
answers
6k
views
Iterate through Python dictionary and special append to new list?
I would like to iterate over a dictionary, and append each key (letter) repeated by the number of times of its value (frequency) to a new list.
For example:
input: {'A':1, 'B':2}. Expected output: [...
-2
votes
1
answer
2k
views
Python create list of objects from dict
I am getting a dict of users and their information
{'Username': 'username', 'Attributes': [{'Name': 'sub', 'Value': 'userSub'}, {'Name': 'email', 'Value': 'email'}
I want to restructure this into an ...
0
votes
1
answer
4k
views
Python Dict Assigning Key-Value in loop
I have a list of variables: [var1, var2, var3, var4].
For var1, I tried the following and it works.
d = dict(var1=True)
f = bdd.cube(d)
Now I want to loop through all variables and for each ...
1
vote
0
answers
19
views
Refactoring code that evaluate only specific values in a Ruby hash
I have a long hash, consisting of some hashes within hashes. Right now I just need to evaluate only a select few of the hash's values.
if params[:my_hash]["start_date(1i)"].empty? || params[:my_hash]...
-1
votes
1
answer
242
views
PHP set value in a foreach loop
i have a problem with foreach in php
i tried to execute this code but at the end $part does not include bought
what's the problem?
foreach ($parts as $part){
foreach ($boughtParts as $...
-4
votes
1
answer
1k
views
Spark Scala - Split Map, Getkey and so on
I have a text file which contains the following:
A>B,C,D
B>A,C,D,E
C>A,B,D,E
D>A,B,C,E
E>B,C,D
I would like to write a Spark-Scala script to obtain the following:
(For each left member,...
2
votes
2
answers
6k
views
Line break not working with jQuery .text()
I have the following code:-
function data(x) {
var dataList = "";
for (var key in obj) {
dataList += key + ": " + obj[key] + "\n"
}
$('#modalText').text(dataList);
...
5
votes
1
answer
2k
views
Iterating through a javascript object to get key-value pairs
Here's my code:
obj = {"TIME":123,"DATE":456}
console.log(obj.TIME);
console.log("---------")
for (var key in obj) {
console.log(key);
console.log(obj.key);
}
It prints as the following:
...
2
votes
2
answers
20k
views
Printing hash value in Perl
When I print a variable, I am getting a HASH(0xd1007d0) value. I need to print the values of all the keys and values. However, I am unable to as the control does not enter the loop.
foreach my $var(...
0
votes
2
answers
373
views
C# - How to create a KeyValuePair with the result of two foreach loops?
So below is the code that I currently have (it doesn't work because the last block sees the arrays an undefined, it's to show what I want to do)
IEnumerable<string> sponsorshipQuery1 =
from ...
0
votes
4
answers
3k
views
Check if an array has a key without a value, then do this (PHP)?
Say I have an array that looks like this:
Array
(
[0] =>
[1] => 2017-01-01 00:00:00
)
How can I dynamically check to see if the area has any empty values?
0
votes
2
answers
998
views
Using integers to access a key, value pairs in a dictionary?
Question: how can i use integer to use as Keys for a dictionary?
Explanation:
I have a dictionary
example = {}
I am populating it with key, value pairs of
A: something
B: something
C: something
1: ...
-1
votes
2
answers
3k
views
ES6 How to convert key, value pair to string recursively in javascript?
I try to interpolate error messages, because I need it in a special text format.
Whats the best practice doing that nowadays :)
thanks for any help!
http://codepen.io/radosch/pen/wWYPYG?editors=1111
...
1
vote
1
answer
203
views
Perl- Get Hash Value from Multi level hash
I have a 3 dimension hash that I need to extract the data in it. I need to extract the name and vendor under vuln_soft-> prod. So far, I manage to extract the "cve_id" by using the following code:
...
0
votes
4
answers
3k
views
Beginner C# Linq: looping through kvp in a dictionary<>
Is this
foreach (KeyValuePair<string, int> kvp in myDic.Select(x => x).ToList())
{
}
and this
foreach (KeyValuePair<string, int> kvp in myDic.ToList())
{
}
...