Skip to main content

All Questions

Filter by
Sorted by
Tagged with
0 votes
1 answer
29 views

How to update the list which is having dictionary data?

Here is the list which is having dictionary data: Fruits = [{'Apple':'10','Banana':'20','Orange':'40'}] I need to update the list by adding 'Grapes':'60'. Expected Output Fruits = [{'Apple':'10','...
Pepper's user avatar
  • 65
0 votes
1 answer
273 views

appending key value pair to existing dictionary values in swift

I'm trying achieve below results. Where I can save multiple key values for multiple string items. //dict["Setting1"] = ["key1":"val1"] //dict["Setting1"] = [&...
dweb's user avatar
  • 161
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: [...
Tim's user avatar
  • 51
0 votes
1 answer
124 views

How to append multiple values in the same key in Python 3?

Unlike the examples i've seen, I think mine is a bit different and so far haven't found anything that could help me out. So here I am again seeking for help. Been working on this for about 3 days now ...
Geni-sama's user avatar
  • 317
2 votes
1 answer
20k views

How to create a list of key:value pairs in a for loop? [duplicate]

I have a for loop which outputs a list of 15 values: for line in data: line # type(line) is `<class 'list'>` # do things with line This line is always a Python list of 11 values, ...
ShanZhengYang's user avatar
2 votes
1 answer
3k views

new dictionary from existing dictionary values

I am trying to figure out how to perform the following: firstDictionary = {"firstKey" : "A", "secondKey" : "B"} secondDictionary = {"firstKey" : 3, "secondKey" : 47} emptyDictionary = {} for key, ...
Zac's user avatar
  • 362
2 votes
3 answers
32k views

Cannot append string to dictionary key

I've been programming for less than four weeks and have run into a problem that I cannot figure out. I'm trying to append a string value to an existing key with an existing string stored in it but if ...
Shahram's user avatar
  • 61
0 votes
4 answers
520 views

Python append to a value in dictionary

I have a following dictionary: d = {'key':{'key2':[]}} Is there any way to append to d['key']? I want to get: d = {'key':{'key2':[], 'key3':[]}} d['key'] = ['key3'] apparently does not produce ...
Stpn's user avatar
  • 6,394