nested dictionary from dict1 and dict2 using keys from dict1 and values from dict2(which are keys in dict1)
up vote
-1
down vote
favorite
users = {'196': ('110', '1'), '186': ('269', '1'), '22': ('68', '4'), '196': ('650', '3')}
movies = {'110': 'Operation Dumbo Drop (1995)', '186': 'Blues Brothers, The (1980)', '269': 'Full Monty, The (1997)', '68': 'Crow, The (1994)', '650': 'Seventh Seal, The (Sjunde inseglet, Det) (1957)'}
My code to create a nested dictionary with keys a unique list of users (keys from users) but using keys from movies to replace values of movies IDs (first item of value list from users) and keeping scores (second item of value list from users) is:
users_preference = {k: list(set().union((*map(lambda x: [x for x in movies.values()], v[0])) )) for k, v in users.items() }
But this returns all movies for each user, and I don't know how to add scores to this. Could you please help? Thank you.
The expected output is similar to:
users_preference = {'196': {'Operation Dumbo Drop (1995)': '1', 'Seventh Seal, The (Sjunde inseglet, Det) (1957)': '3'}
python dictionary nested
|
show 2 more comments
up vote
-1
down vote
favorite
users = {'196': ('110', '1'), '186': ('269', '1'), '22': ('68', '4'), '196': ('650', '3')}
movies = {'110': 'Operation Dumbo Drop (1995)', '186': 'Blues Brothers, The (1980)', '269': 'Full Monty, The (1997)', '68': 'Crow, The (1994)', '650': 'Seventh Seal, The (Sjunde inseglet, Det) (1957)'}
My code to create a nested dictionary with keys a unique list of users (keys from users) but using keys from movies to replace values of movies IDs (first item of value list from users) and keeping scores (second item of value list from users) is:
users_preference = {k: list(set().union((*map(lambda x: [x for x in movies.values()], v[0])) )) for k, v in users.items() }
But this returns all movies for each user, and I don't know how to add scores to this. Could you please help? Thank you.
The expected output is similar to:
users_preference = {'196': {'Operation Dumbo Drop (1995)': '1', 'Seventh Seal, The (Sjunde inseglet, Det) (1957)': '3'}
python dictionary nested
It would be very helpful if you posted your expected output instead of just describing it in words.
– timgeb
2 days ago
Why do these users have a 2-tuple with'1'
?
– Willem Van Onsem
2 days ago
Sorry yes the expected output: `Dct3 = {'196': {'Operation Dumbo Drop (1995)': '1', 'Seventh Seal, The (Sjunde inseglet, Det) (1957)': '3'}
– LMHull
2 days ago
@LMHull edit the expected output into your question, please. Don't post it as a comment.
– timgeb
2 days ago
1
There is a duplicated key on the users dictionary '196'.
– Daniel Mesejo
2 days ago
|
show 2 more comments
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
users = {'196': ('110', '1'), '186': ('269', '1'), '22': ('68', '4'), '196': ('650', '3')}
movies = {'110': 'Operation Dumbo Drop (1995)', '186': 'Blues Brothers, The (1980)', '269': 'Full Monty, The (1997)', '68': 'Crow, The (1994)', '650': 'Seventh Seal, The (Sjunde inseglet, Det) (1957)'}
My code to create a nested dictionary with keys a unique list of users (keys from users) but using keys from movies to replace values of movies IDs (first item of value list from users) and keeping scores (second item of value list from users) is:
users_preference = {k: list(set().union((*map(lambda x: [x for x in movies.values()], v[0])) )) for k, v in users.items() }
But this returns all movies for each user, and I don't know how to add scores to this. Could you please help? Thank you.
The expected output is similar to:
users_preference = {'196': {'Operation Dumbo Drop (1995)': '1', 'Seventh Seal, The (Sjunde inseglet, Det) (1957)': '3'}
python dictionary nested
users = {'196': ('110', '1'), '186': ('269', '1'), '22': ('68', '4'), '196': ('650', '3')}
movies = {'110': 'Operation Dumbo Drop (1995)', '186': 'Blues Brothers, The (1980)', '269': 'Full Monty, The (1997)', '68': 'Crow, The (1994)', '650': 'Seventh Seal, The (Sjunde inseglet, Det) (1957)'}
My code to create a nested dictionary with keys a unique list of users (keys from users) but using keys from movies to replace values of movies IDs (first item of value list from users) and keeping scores (second item of value list from users) is:
users_preference = {k: list(set().union((*map(lambda x: [x for x in movies.values()], v[0])) )) for k, v in users.items() }
But this returns all movies for each user, and I don't know how to add scores to this. Could you please help? Thank you.
The expected output is similar to:
users_preference = {'196': {'Operation Dumbo Drop (1995)': '1', 'Seventh Seal, The (Sjunde inseglet, Det) (1957)': '3'}
python dictionary nested
python dictionary nested
edited 2 days ago
timgeb
43k105883
43k105883
asked 2 days ago
LMHull
426
426
It would be very helpful if you posted your expected output instead of just describing it in words.
– timgeb
2 days ago
Why do these users have a 2-tuple with'1'
?
– Willem Van Onsem
2 days ago
Sorry yes the expected output: `Dct3 = {'196': {'Operation Dumbo Drop (1995)': '1', 'Seventh Seal, The (Sjunde inseglet, Det) (1957)': '3'}
– LMHull
2 days ago
@LMHull edit the expected output into your question, please. Don't post it as a comment.
– timgeb
2 days ago
1
There is a duplicated key on the users dictionary '196'.
– Daniel Mesejo
2 days ago
|
show 2 more comments
It would be very helpful if you posted your expected output instead of just describing it in words.
– timgeb
2 days ago
Why do these users have a 2-tuple with'1'
?
– Willem Van Onsem
2 days ago
Sorry yes the expected output: `Dct3 = {'196': {'Operation Dumbo Drop (1995)': '1', 'Seventh Seal, The (Sjunde inseglet, Det) (1957)': '3'}
– LMHull
2 days ago
@LMHull edit the expected output into your question, please. Don't post it as a comment.
– timgeb
2 days ago
1
There is a duplicated key on the users dictionary '196'.
– Daniel Mesejo
2 days ago
It would be very helpful if you posted your expected output instead of just describing it in words.
– timgeb
2 days ago
It would be very helpful if you posted your expected output instead of just describing it in words.
– timgeb
2 days ago
Why do these users have a 2-tuple with
'1'
?– Willem Van Onsem
2 days ago
Why do these users have a 2-tuple with
'1'
?– Willem Van Onsem
2 days ago
Sorry yes the expected output: `Dct3 = {'196': {'Operation Dumbo Drop (1995)': '1', 'Seventh Seal, The (Sjunde inseglet, Det) (1957)': '3'}
– LMHull
2 days ago
Sorry yes the expected output: `Dct3 = {'196': {'Operation Dumbo Drop (1995)': '1', 'Seventh Seal, The (Sjunde inseglet, Det) (1957)': '3'}
– LMHull
2 days ago
@LMHull edit the expected output into your question, please. Don't post it as a comment.
– timgeb
2 days ago
@LMHull edit the expected output into your question, please. Don't post it as a comment.
– timgeb
2 days ago
1
1
There is a duplicated key on the users dictionary '196'.
– Daniel Mesejo
2 days ago
There is a duplicated key on the users dictionary '196'.
– Daniel Mesejo
2 days ago
|
show 2 more comments
4 Answers
4
active
oldest
votes
up vote
0
down vote
accepted
The expected output cannot be achieved using the format of users
, I suggest you change to a dictionary where the values are a list of tuples:
users = {'196': [('110', '1'), ('650', '3')], '186': [('269', '1')], '22': [('68', '4')]}
movies = {'110': 'Operation Dumbo Drop (1995)', '186': 'Blues Brothers, The (1980)', '269': 'Full Monty, The (1997)',
'68': 'Crow, The (1994)', '650': 'Seventh Seal, The (Sjunde inseglet, Det) (1957)'}
user_preference = {user: {movies.get(movie, movie): rank for movie, rank in preferences} for user, preferences in
users.items()}
print(user_preference)
Output
{'196': {'Operation Dumbo Drop (1995)': '1', 'Seventh Seal, The (Sjunde inseglet, Det) (1957)': '3'}, '22': {'Crow, The (1994)': '4'}, '186': {'Full Monty, The (1997)': '1'}}
You are actually so right about this. I have got the wrong dictionaryusers
! I am iterating through a data file to getusers
and so far I have picked up just one movie per user, instead of list of tuples as you very correctly suggested. Thanks for your attention to detail.
– LMHull
2 days ago
add a comment |
up vote
1
down vote
Dct3 = {k:(movies[v[0]],v[1]) for k, v in users.items()}
Keep it simple, you can use keys to access values from movies dict.
Just think of it as creating a new tuple as values for each key in users.
New contributor
Thank you very much, really appreciate it. I feel so much better know after so many hours of trying this.
– LMHull
2 days ago
No worries at all, welcome to the world of programming :) @LMHull
– Paritosh Singh
2 days ago
add a comment |
up vote
1
down vote
More verbose
Dct3 = {}
for k, v in users.items():
v = list(v)
v[0] = movies[v[0]]
Dct3[k] = v
print (Dct3)
#=> {'196': ['Seventh Seal, The (Sjunde inseglet, Det) (1957)', '3'], '186': ['Full Monty, The (1997)', '1'], '22': ['Crow, The (1994)', '4']}
1
Thank you very much. I really appreciate your help.
– LMHull
2 days ago
add a comment |
up vote
0
down vote
You can issue
{user:(movies[movie_id], score) for user, (movie_id, score) in users.items()}
which produces
{'186': ('Full Monty, The (1997)', '1'),
'196': ('Seventh Seal, The (Sjunde inseglet, Det) (1957)', '3'),
'22': ('Crow, The (1994)', '4')}
Note that there is a duplicate key in your dictionary users
('196'
). (Pointed out by Daniel Mesejo in the comments.) Dictionary keys must be unique, so users
actually looks like this:
>>> users
>>> {'186': ('269', '1'), '196': ('650', '3'), '22': ('68', '4')}
~edit~
Traditional for
loop that does the same.
result = {}
for user, (movie_id, score) in users.items():
result[user] = (movies[movie_id], score)
Excellent, thank you so much. I am learning python so I didn't know that keys must be unique. Very happy now, embarrassingly I tried to do this for about 5 hours...
– LMHull
2 days ago
@LMHull If you are new to Python, my tip is to stick to traditionalfor
loops before writing oneliners. Once you figured out how the different data structures operate, you can venture into list-, dict- and set-comprehensions.
– timgeb
2 days ago
I will do, thanks for your advice.
– LMHull
2 days ago
add a comment |
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
The expected output cannot be achieved using the format of users
, I suggest you change to a dictionary where the values are a list of tuples:
users = {'196': [('110', '1'), ('650', '3')], '186': [('269', '1')], '22': [('68', '4')]}
movies = {'110': 'Operation Dumbo Drop (1995)', '186': 'Blues Brothers, The (1980)', '269': 'Full Monty, The (1997)',
'68': 'Crow, The (1994)', '650': 'Seventh Seal, The (Sjunde inseglet, Det) (1957)'}
user_preference = {user: {movies.get(movie, movie): rank for movie, rank in preferences} for user, preferences in
users.items()}
print(user_preference)
Output
{'196': {'Operation Dumbo Drop (1995)': '1', 'Seventh Seal, The (Sjunde inseglet, Det) (1957)': '3'}, '22': {'Crow, The (1994)': '4'}, '186': {'Full Monty, The (1997)': '1'}}
You are actually so right about this. I have got the wrong dictionaryusers
! I am iterating through a data file to getusers
and so far I have picked up just one movie per user, instead of list of tuples as you very correctly suggested. Thanks for your attention to detail.
– LMHull
2 days ago
add a comment |
up vote
0
down vote
accepted
The expected output cannot be achieved using the format of users
, I suggest you change to a dictionary where the values are a list of tuples:
users = {'196': [('110', '1'), ('650', '3')], '186': [('269', '1')], '22': [('68', '4')]}
movies = {'110': 'Operation Dumbo Drop (1995)', '186': 'Blues Brothers, The (1980)', '269': 'Full Monty, The (1997)',
'68': 'Crow, The (1994)', '650': 'Seventh Seal, The (Sjunde inseglet, Det) (1957)'}
user_preference = {user: {movies.get(movie, movie): rank for movie, rank in preferences} for user, preferences in
users.items()}
print(user_preference)
Output
{'196': {'Operation Dumbo Drop (1995)': '1', 'Seventh Seal, The (Sjunde inseglet, Det) (1957)': '3'}, '22': {'Crow, The (1994)': '4'}, '186': {'Full Monty, The (1997)': '1'}}
You are actually so right about this. I have got the wrong dictionaryusers
! I am iterating through a data file to getusers
and so far I have picked up just one movie per user, instead of list of tuples as you very correctly suggested. Thanks for your attention to detail.
– LMHull
2 days ago
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
The expected output cannot be achieved using the format of users
, I suggest you change to a dictionary where the values are a list of tuples:
users = {'196': [('110', '1'), ('650', '3')], '186': [('269', '1')], '22': [('68', '4')]}
movies = {'110': 'Operation Dumbo Drop (1995)', '186': 'Blues Brothers, The (1980)', '269': 'Full Monty, The (1997)',
'68': 'Crow, The (1994)', '650': 'Seventh Seal, The (Sjunde inseglet, Det) (1957)'}
user_preference = {user: {movies.get(movie, movie): rank for movie, rank in preferences} for user, preferences in
users.items()}
print(user_preference)
Output
{'196': {'Operation Dumbo Drop (1995)': '1', 'Seventh Seal, The (Sjunde inseglet, Det) (1957)': '3'}, '22': {'Crow, The (1994)': '4'}, '186': {'Full Monty, The (1997)': '1'}}
The expected output cannot be achieved using the format of users
, I suggest you change to a dictionary where the values are a list of tuples:
users = {'196': [('110', '1'), ('650', '3')], '186': [('269', '1')], '22': [('68', '4')]}
movies = {'110': 'Operation Dumbo Drop (1995)', '186': 'Blues Brothers, The (1980)', '269': 'Full Monty, The (1997)',
'68': 'Crow, The (1994)', '650': 'Seventh Seal, The (Sjunde inseglet, Det) (1957)'}
user_preference = {user: {movies.get(movie, movie): rank for movie, rank in preferences} for user, preferences in
users.items()}
print(user_preference)
Output
{'196': {'Operation Dumbo Drop (1995)': '1', 'Seventh Seal, The (Sjunde inseglet, Det) (1957)': '3'}, '22': {'Crow, The (1994)': '4'}, '186': {'Full Monty, The (1997)': '1'}}
answered 2 days ago
Daniel Mesejo
7,6341821
7,6341821
You are actually so right about this. I have got the wrong dictionaryusers
! I am iterating through a data file to getusers
and so far I have picked up just one movie per user, instead of list of tuples as you very correctly suggested. Thanks for your attention to detail.
– LMHull
2 days ago
add a comment |
You are actually so right about this. I have got the wrong dictionaryusers
! I am iterating through a data file to getusers
and so far I have picked up just one movie per user, instead of list of tuples as you very correctly suggested. Thanks for your attention to detail.
– LMHull
2 days ago
You are actually so right about this. I have got the wrong dictionary
users
! I am iterating through a data file to get users
and so far I have picked up just one movie per user, instead of list of tuples as you very correctly suggested. Thanks for your attention to detail.– LMHull
2 days ago
You are actually so right about this. I have got the wrong dictionary
users
! I am iterating through a data file to get users
and so far I have picked up just one movie per user, instead of list of tuples as you very correctly suggested. Thanks for your attention to detail.– LMHull
2 days ago
add a comment |
up vote
1
down vote
Dct3 = {k:(movies[v[0]],v[1]) for k, v in users.items()}
Keep it simple, you can use keys to access values from movies dict.
Just think of it as creating a new tuple as values for each key in users.
New contributor
Thank you very much, really appreciate it. I feel so much better know after so many hours of trying this.
– LMHull
2 days ago
No worries at all, welcome to the world of programming :) @LMHull
– Paritosh Singh
2 days ago
add a comment |
up vote
1
down vote
Dct3 = {k:(movies[v[0]],v[1]) for k, v in users.items()}
Keep it simple, you can use keys to access values from movies dict.
Just think of it as creating a new tuple as values for each key in users.
New contributor
Thank you very much, really appreciate it. I feel so much better know after so many hours of trying this.
– LMHull
2 days ago
No worries at all, welcome to the world of programming :) @LMHull
– Paritosh Singh
2 days ago
add a comment |
up vote
1
down vote
up vote
1
down vote
Dct3 = {k:(movies[v[0]],v[1]) for k, v in users.items()}
Keep it simple, you can use keys to access values from movies dict.
Just think of it as creating a new tuple as values for each key in users.
New contributor
Dct3 = {k:(movies[v[0]],v[1]) for k, v in users.items()}
Keep it simple, you can use keys to access values from movies dict.
Just think of it as creating a new tuple as values for each key in users.
New contributor
New contributor
answered 2 days ago
Paritosh Singh
1665
1665
New contributor
New contributor
Thank you very much, really appreciate it. I feel so much better know after so many hours of trying this.
– LMHull
2 days ago
No worries at all, welcome to the world of programming :) @LMHull
– Paritosh Singh
2 days ago
add a comment |
Thank you very much, really appreciate it. I feel so much better know after so many hours of trying this.
– LMHull
2 days ago
No worries at all, welcome to the world of programming :) @LMHull
– Paritosh Singh
2 days ago
Thank you very much, really appreciate it. I feel so much better know after so many hours of trying this.
– LMHull
2 days ago
Thank you very much, really appreciate it. I feel so much better know after so many hours of trying this.
– LMHull
2 days ago
No worries at all, welcome to the world of programming :) @LMHull
– Paritosh Singh
2 days ago
No worries at all, welcome to the world of programming :) @LMHull
– Paritosh Singh
2 days ago
add a comment |
up vote
1
down vote
More verbose
Dct3 = {}
for k, v in users.items():
v = list(v)
v[0] = movies[v[0]]
Dct3[k] = v
print (Dct3)
#=> {'196': ['Seventh Seal, The (Sjunde inseglet, Det) (1957)', '3'], '186': ['Full Monty, The (1997)', '1'], '22': ['Crow, The (1994)', '4']}
1
Thank you very much. I really appreciate your help.
– LMHull
2 days ago
add a comment |
up vote
1
down vote
More verbose
Dct3 = {}
for k, v in users.items():
v = list(v)
v[0] = movies[v[0]]
Dct3[k] = v
print (Dct3)
#=> {'196': ['Seventh Seal, The (Sjunde inseglet, Det) (1957)', '3'], '186': ['Full Monty, The (1997)', '1'], '22': ['Crow, The (1994)', '4']}
1
Thank you very much. I really appreciate your help.
– LMHull
2 days ago
add a comment |
up vote
1
down vote
up vote
1
down vote
More verbose
Dct3 = {}
for k, v in users.items():
v = list(v)
v[0] = movies[v[0]]
Dct3[k] = v
print (Dct3)
#=> {'196': ['Seventh Seal, The (Sjunde inseglet, Det) (1957)', '3'], '186': ['Full Monty, The (1997)', '1'], '22': ['Crow, The (1994)', '4']}
More verbose
Dct3 = {}
for k, v in users.items():
v = list(v)
v[0] = movies[v[0]]
Dct3[k] = v
print (Dct3)
#=> {'196': ['Seventh Seal, The (Sjunde inseglet, Det) (1957)', '3'], '186': ['Full Monty, The (1997)', '1'], '22': ['Crow, The (1994)', '4']}
answered 2 days ago
iGian
2,2832620
2,2832620
1
Thank you very much. I really appreciate your help.
– LMHull
2 days ago
add a comment |
1
Thank you very much. I really appreciate your help.
– LMHull
2 days ago
1
1
Thank you very much. I really appreciate your help.
– LMHull
2 days ago
Thank you very much. I really appreciate your help.
– LMHull
2 days ago
add a comment |
up vote
0
down vote
You can issue
{user:(movies[movie_id], score) for user, (movie_id, score) in users.items()}
which produces
{'186': ('Full Monty, The (1997)', '1'),
'196': ('Seventh Seal, The (Sjunde inseglet, Det) (1957)', '3'),
'22': ('Crow, The (1994)', '4')}
Note that there is a duplicate key in your dictionary users
('196'
). (Pointed out by Daniel Mesejo in the comments.) Dictionary keys must be unique, so users
actually looks like this:
>>> users
>>> {'186': ('269', '1'), '196': ('650', '3'), '22': ('68', '4')}
~edit~
Traditional for
loop that does the same.
result = {}
for user, (movie_id, score) in users.items():
result[user] = (movies[movie_id], score)
Excellent, thank you so much. I am learning python so I didn't know that keys must be unique. Very happy now, embarrassingly I tried to do this for about 5 hours...
– LMHull
2 days ago
@LMHull If you are new to Python, my tip is to stick to traditionalfor
loops before writing oneliners. Once you figured out how the different data structures operate, you can venture into list-, dict- and set-comprehensions.
– timgeb
2 days ago
I will do, thanks for your advice.
– LMHull
2 days ago
add a comment |
up vote
0
down vote
You can issue
{user:(movies[movie_id], score) for user, (movie_id, score) in users.items()}
which produces
{'186': ('Full Monty, The (1997)', '1'),
'196': ('Seventh Seal, The (Sjunde inseglet, Det) (1957)', '3'),
'22': ('Crow, The (1994)', '4')}
Note that there is a duplicate key in your dictionary users
('196'
). (Pointed out by Daniel Mesejo in the comments.) Dictionary keys must be unique, so users
actually looks like this:
>>> users
>>> {'186': ('269', '1'), '196': ('650', '3'), '22': ('68', '4')}
~edit~
Traditional for
loop that does the same.
result = {}
for user, (movie_id, score) in users.items():
result[user] = (movies[movie_id], score)
Excellent, thank you so much. I am learning python so I didn't know that keys must be unique. Very happy now, embarrassingly I tried to do this for about 5 hours...
– LMHull
2 days ago
@LMHull If you are new to Python, my tip is to stick to traditionalfor
loops before writing oneliners. Once you figured out how the different data structures operate, you can venture into list-, dict- and set-comprehensions.
– timgeb
2 days ago
I will do, thanks for your advice.
– LMHull
2 days ago
add a comment |
up vote
0
down vote
up vote
0
down vote
You can issue
{user:(movies[movie_id], score) for user, (movie_id, score) in users.items()}
which produces
{'186': ('Full Monty, The (1997)', '1'),
'196': ('Seventh Seal, The (Sjunde inseglet, Det) (1957)', '3'),
'22': ('Crow, The (1994)', '4')}
Note that there is a duplicate key in your dictionary users
('196'
). (Pointed out by Daniel Mesejo in the comments.) Dictionary keys must be unique, so users
actually looks like this:
>>> users
>>> {'186': ('269', '1'), '196': ('650', '3'), '22': ('68', '4')}
~edit~
Traditional for
loop that does the same.
result = {}
for user, (movie_id, score) in users.items():
result[user] = (movies[movie_id], score)
You can issue
{user:(movies[movie_id], score) for user, (movie_id, score) in users.items()}
which produces
{'186': ('Full Monty, The (1997)', '1'),
'196': ('Seventh Seal, The (Sjunde inseglet, Det) (1957)', '3'),
'22': ('Crow, The (1994)', '4')}
Note that there is a duplicate key in your dictionary users
('196'
). (Pointed out by Daniel Mesejo in the comments.) Dictionary keys must be unique, so users
actually looks like this:
>>> users
>>> {'186': ('269', '1'), '196': ('650', '3'), '22': ('68', '4')}
~edit~
Traditional for
loop that does the same.
result = {}
for user, (movie_id, score) in users.items():
result[user] = (movies[movie_id], score)
edited 2 days ago
answered 2 days ago
timgeb
43k105883
43k105883
Excellent, thank you so much. I am learning python so I didn't know that keys must be unique. Very happy now, embarrassingly I tried to do this for about 5 hours...
– LMHull
2 days ago
@LMHull If you are new to Python, my tip is to stick to traditionalfor
loops before writing oneliners. Once you figured out how the different data structures operate, you can venture into list-, dict- and set-comprehensions.
– timgeb
2 days ago
I will do, thanks for your advice.
– LMHull
2 days ago
add a comment |
Excellent, thank you so much. I am learning python so I didn't know that keys must be unique. Very happy now, embarrassingly I tried to do this for about 5 hours...
– LMHull
2 days ago
@LMHull If you are new to Python, my tip is to stick to traditionalfor
loops before writing oneliners. Once you figured out how the different data structures operate, you can venture into list-, dict- and set-comprehensions.
– timgeb
2 days ago
I will do, thanks for your advice.
– LMHull
2 days ago
Excellent, thank you so much. I am learning python so I didn't know that keys must be unique. Very happy now, embarrassingly I tried to do this for about 5 hours...
– LMHull
2 days ago
Excellent, thank you so much. I am learning python so I didn't know that keys must be unique. Very happy now, embarrassingly I tried to do this for about 5 hours...
– LMHull
2 days ago
@LMHull If you are new to Python, my tip is to stick to traditional
for
loops before writing oneliners. Once you figured out how the different data structures operate, you can venture into list-, dict- and set-comprehensions.– timgeb
2 days ago
@LMHull If you are new to Python, my tip is to stick to traditional
for
loops before writing oneliners. Once you figured out how the different data structures operate, you can venture into list-, dict- and set-comprehensions.– timgeb
2 days ago
I will do, thanks for your advice.
– LMHull
2 days ago
I will do, thanks for your advice.
– LMHull
2 days ago
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239262%2fnested-dictionary-from-dict1-and-dict2-using-keys-from-dict1-and-values-from-dic%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
It would be very helpful if you posted your expected output instead of just describing it in words.
– timgeb
2 days ago
Why do these users have a 2-tuple with
'1'
?– Willem Van Onsem
2 days ago
Sorry yes the expected output: `Dct3 = {'196': {'Operation Dumbo Drop (1995)': '1', 'Seventh Seal, The (Sjunde inseglet, Det) (1957)': '3'}
– LMHull
2 days ago
@LMHull edit the expected output into your question, please. Don't post it as a comment.
– timgeb
2 days ago
1
There is a duplicated key on the users dictionary '196'.
– Daniel Mesejo
2 days ago