Range Over Built in Logo
Based on the instructions and the input provided, here is the translation from the original Go code example to Python along with the explanation.
Python does not have a range
function that works exactly like it does in the provided Go code example for slices, maps, and strings, but it does offer similar constructs. Here is how you can translate those examples idiomatically in Python:
range
on lists provides both the index and value for each entry. Above we didn’t need the index, so we ignored it with the blank identifier _
. Sometimes we actually want the indexes though.
rang
on dictionaries iterates over key/value pairs.
range
can also iterate over just the keys of a dictionary.
range
on strings iterates over Unicode code points. The first value is the starting byte index of the character and the second the character itself.
Running this Python code will give the following output: