英文:
In Go how can I iterate over a pointer list?
问题
我想遍历这个:
*list.List
我该怎么做?
func Foo(key string, values *list.List) string {
...
//我想遍历并从"values"中获取值
}
这个Foo函数被这样调用:
kvs := make(map[string]*list.List)
res := Foo(k, kvs[k]) //k是字符串
谢谢!
英文:
I want to iterate over this :
*list.List
How can I do it?
func Foo(key string, values *list.List) string {
...
//I want to iterate and get value from "values"
}
this Foo is being called like this:
kvs := make(map[string]*list.List)
res := Foo(k, kvs[k]) //k is string
Thanks!
答案1
得分: 9
请检查示例@ http://golang.org/pkg/container/list/ :
func Foo(key string, vl *list.List) string {
for e := l.Front(); e != nil; e = e.Next() {
v := e.Value
}
return ""
}
//edit : 请查看https://stackoverflow.com/questions/12677934/create-a-golang-map-of-lists?rq=1
英文:
Check the example @ http://golang.org/pkg/container/list/ :
func Foo(key string, vl *list.List) string {
for e := l.Front(); e != nil; e = e.Next() {
v := e.Value
}
return ""
}
//edit : check https://stackoverflow.com/questions/12677934/create-a-golang-map-of-lists?rq=1
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论