How to add just key in dict? [on hold]
$begingroup$
I have some dict to add:
p = {('S', 'A'): (2, 2)}
x = {'D' : (3, 3)}
my code is:
p.update(x)
print(p)
output:
{('S', 'A'): (2, 2), 'D': (3, 3)}
but, my expected output is:
{('S', 'A', 'D'): (5, 5)}
python
New contributor
$endgroup$
put on hold as off-topic by Dawny33♦ 17 hours ago
- This question does not appear to be about data science, within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
$begingroup$
I have some dict to add:
p = {('S', 'A'): (2, 2)}
x = {'D' : (3, 3)}
my code is:
p.update(x)
print(p)
output:
{('S', 'A'): (2, 2), 'D': (3, 3)}
but, my expected output is:
{('S', 'A', 'D'): (5, 5)}
python
New contributor
$endgroup$
put on hold as off-topic by Dawny33♦ 17 hours ago
- This question does not appear to be about data science, within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.
$begingroup$
You are not adding anything, right? You are changing the key, as I understand from your question
$endgroup$
– Dawny33♦
18 hours ago
$begingroup$
yes for values. i just update a dict. sum of values is not yet.
$endgroup$
– lilis gumilang
18 hours ago
$begingroup$
Hi @lilisgumilang, this question seems to be about programming and not about data science. Therefore, it would be better if you ask it in stackoverflow.
$endgroup$
– ncasas
17 hours ago
$begingroup$
The update method is doing what it should. You want to actually change the dictionary key by updating the tuple. You cannot do that directly, as dict keys (as a necessity) are immutable (unchangeable).
$endgroup$
– n1k31t4
12 hours ago
add a comment |
$begingroup$
I have some dict to add:
p = {('S', 'A'): (2, 2)}
x = {'D' : (3, 3)}
my code is:
p.update(x)
print(p)
output:
{('S', 'A'): (2, 2), 'D': (3, 3)}
but, my expected output is:
{('S', 'A', 'D'): (5, 5)}
python
New contributor
$endgroup$
I have some dict to add:
p = {('S', 'A'): (2, 2)}
x = {'D' : (3, 3)}
my code is:
p.update(x)
print(p)
output:
{('S', 'A'): (2, 2), 'D': (3, 3)}
but, my expected output is:
{('S', 'A', 'D'): (5, 5)}
python
python
New contributor
New contributor
New contributor
asked 19 hours ago
lilis gumilanglilis gumilang
6
6
New contributor
New contributor
put on hold as off-topic by Dawny33♦ 17 hours ago
- This question does not appear to be about data science, within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.
put on hold as off-topic by Dawny33♦ 17 hours ago
- This question does not appear to be about data science, within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.
$begingroup$
You are not adding anything, right? You are changing the key, as I understand from your question
$endgroup$
– Dawny33♦
18 hours ago
$begingroup$
yes for values. i just update a dict. sum of values is not yet.
$endgroup$
– lilis gumilang
18 hours ago
$begingroup$
Hi @lilisgumilang, this question seems to be about programming and not about data science. Therefore, it would be better if you ask it in stackoverflow.
$endgroup$
– ncasas
17 hours ago
$begingroup$
The update method is doing what it should. You want to actually change the dictionary key by updating the tuple. You cannot do that directly, as dict keys (as a necessity) are immutable (unchangeable).
$endgroup$
– n1k31t4
12 hours ago
add a comment |
$begingroup$
You are not adding anything, right? You are changing the key, as I understand from your question
$endgroup$
– Dawny33♦
18 hours ago
$begingroup$
yes for values. i just update a dict. sum of values is not yet.
$endgroup$
– lilis gumilang
18 hours ago
$begingroup$
Hi @lilisgumilang, this question seems to be about programming and not about data science. Therefore, it would be better if you ask it in stackoverflow.
$endgroup$
– ncasas
17 hours ago
$begingroup$
The update method is doing what it should. You want to actually change the dictionary key by updating the tuple. You cannot do that directly, as dict keys (as a necessity) are immutable (unchangeable).
$endgroup$
– n1k31t4
12 hours ago
$begingroup$
You are not adding anything, right? You are changing the key, as I understand from your question
$endgroup$
– Dawny33♦
18 hours ago
$begingroup$
You are not adding anything, right? You are changing the key, as I understand from your question
$endgroup$
– Dawny33♦
18 hours ago
$begingroup$
yes for values. i just update a dict. sum of values is not yet.
$endgroup$
– lilis gumilang
18 hours ago
$begingroup$
yes for values. i just update a dict. sum of values is not yet.
$endgroup$
– lilis gumilang
18 hours ago
$begingroup$
Hi @lilisgumilang, this question seems to be about programming and not about data science. Therefore, it would be better if you ask it in stackoverflow.
$endgroup$
– ncasas
17 hours ago
$begingroup$
Hi @lilisgumilang, this question seems to be about programming and not about data science. Therefore, it would be better if you ask it in stackoverflow.
$endgroup$
– ncasas
17 hours ago
$begingroup$
The update method is doing what it should. You want to actually change the dictionary key by updating the tuple. You cannot do that directly, as dict keys (as a necessity) are immutable (unchangeable).
$endgroup$
– n1k31t4
12 hours ago
$begingroup$
The update method is doing what it should. You want to actually change the dictionary key by updating the tuple. You cannot do that directly, as dict keys (as a necessity) are immutable (unchangeable).
$endgroup$
– n1k31t4
12 hours ago
add a comment |
0
active
oldest
votes
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
You are not adding anything, right? You are changing the key, as I understand from your question
$endgroup$
– Dawny33♦
18 hours ago
$begingroup$
yes for values. i just update a dict. sum of values is not yet.
$endgroup$
– lilis gumilang
18 hours ago
$begingroup$
Hi @lilisgumilang, this question seems to be about programming and not about data science. Therefore, it would be better if you ask it in stackoverflow.
$endgroup$
– ncasas
17 hours ago
$begingroup$
The update method is doing what it should. You want to actually change the dictionary key by updating the tuple. You cannot do that directly, as dict keys (as a necessity) are immutable (unchangeable).
$endgroup$
– n1k31t4
12 hours ago