MRAB wrote:
Tino Wildenhain wrote:Xah Lee wrote:comp.lang.lisp,comp.lang.scheme,comp.lang.functional,comp.lang.python,comp.lang.ruby...OK, I want to create a nested list in Lisp (always of only integers) from a text file, such that each line in the text file would be represented as a sublist in the 'imported' list. example of a file's content 3 10 2 4 1 11 18 example of programing behavior (make-list-from-text "blob.txt") => ((3 10 2) (4 1) (11 18))In a show-off context, it can be reduced to by about 50%, but still far verbose than ruby or say perl (which is 1 or 2 lines. (python would be 3 or 5)).So? Please count the lines: [line.strip().split() for line in file("blob.txt")]The original requirement was for a list of lists of integers:
Actually I read: "Note that the result element is string, not numbers. There's no easy way to convert them on the fly. 3 or so more lines will be needed to do that." So I felt that requirement was dropped, but otherwise, you are right :-)
[[int(x) for x in line.split()] for line in open("blob.txt")] Still only 1 line, though.
Yep. Regards Tino
smime.p7s
Description: S/MIME Cryptographic Signature
-- http://mail.python.org/mailman/listinfo/python-list