Open stefanuytterhoeven opened 4 months ago
Do you mind fixing the formatting of your repro (by wrapping the code in triple backquote)?
Do you mind fixing the formatting of your repro (by wrapping the code in triple backquote)?
done :)
You don't need to wrap your String
key in a StringKey
struct any more in 24.1. The following works:
from collections import Dict
fn main():
var d = Dict[String, Int]()
d["a"] = 1
for t in d.items():
print(t[].key, t[].value)
Bug description
test program:
start source
from collections.dict import Dict, KeyElement
end source
Problem: for e in s.items() statements: according to the documentation it has to be
but this gives errors: error: no matching function in call to 'print': note: candidate not viable: expected at most 0 positional arguments, got 2 note: candidate not viable: expected at most 1 positional arguments, got 2 note: candidate not viable: expected at most 1 positional arguments, got 2 ....
when playing with it,
works. e[].key cannot be used, but e[].key.s can be used. I guess the "s" is from the StringKey struct
This is not how it's documented.
Steps to reproduce
System information
UPDATE: since release mojo 24.1.0 , no need to create the stringkey struct ? apparently you can create a dict by var newdict=Dict[String,String]() newdict["testkey1]="testvalue1"
This WORKS. But, the documentation about DICT isnt updated yet.