I'd like the convienience of
for i, line in enumerate(open(sys.argv[1])): print i, line
when doing the following in Scala
for (line <- Source.fromFile(args(0)).getLines()) { println(line) }
You can use the zipWithIndex from Iterable trait:
zipWithIndex
for ((line, i) <- Source.fromFile(args(0)).getLines().zipWithIndex) { println(i, line) }
2.1m questions
2.1m answers
60 comments
57.0k users