Loading

Memo# Loop with index in Ruby (alternative to enumerate in Python)

irb(main):033:0* d={"a"=>"x","b"=>"y","c"=>"z"}
=> {"a"=>"x", "b"=>"y", "c"=>"z"}

irb(main):052:0> d.each_with_index{|(k,v),i|puts "key: %s, value: %s, index: %i"% [k,v,i]}
key: a, value: x, index: 0
key: b, value: y, index: 1
key: c, value: z, index: 2
=> {"a"=>"x", "b"=>"y", "c"=>"z"}

No comments:

က်ေနာ္ဖတ္ေသာ အျခား ဘေလာ့ / ဆိုဒ္မ်ား