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) }
1.4m articles
1.4m replys
5 comments
57.0k users