Groups
Groups
Sign in
Groups
Groups
golang-nuts
Conversations
About
Send feedback
Help
Iterate over two maps at once
2,192 views
Skip to first unread message
Tibi
unread,
Jul 4, 2011, 3:03:53 PM
7/4/11
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golan...@googlegroups.com
Hello,
I would like to iterate at once over two maps that have common keys but they also have different keys. I only care about the common keys.
In C++, I would do this with iterators, but in Go I can only iterate with range. The problem is that I have to choose which map to iterate over.
Any clues?
Tibor
jimmy frasche
unread,
Jul 4, 2011, 3:07:05 PM
7/4/11
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golan...@googlegroups.com
If you only care about the common keys why not just arbitrarily pick
one map and in each iteration continue if the key is not in the other
map like
var a, b map[something]something
....
for k, v := range a {
if v2, ok := b[k]; ok {
//code
Reply all
Reply to author
Forward
0 new messages