TheBeege
TheBeege
MModular
Created by TheBeege on 4/13/2024 in #questions
What's the proper way to use List?
okay, cool. that'll work. thank you!
4 replies
MModular
Created by TheBeege on 4/13/2024 in #questions
What's the proper way to use List?
it's gross, but i've answered my own question. i found the example here: https://docs.modular.com/mojo/manual/traits#generic-structs-with-traits looks like List doesn't support direct iteration, but it does support Python-style accessing. this works:
from collections import List

fn main():
var my_list: List[Int] = List(1, 2, 3)
for i in range(len(my_list)):
for j in range(my_list[i]):
print("counting: ", j)
from collections import List

fn main():
var my_list: List[Int] = List(1, 2, 3)
for i in range(len(my_list)):
for j in range(my_list[i]):
print("counting: ", j)
4 replies