對不起,有點遲了,正如在jkilky的評論中所建議的那樣,我將使用通用的lisp庫cl-csv,它可以通過quicklisp獲得。
CL-USER> (ql:quickload :cl-csv)
To load "cl-csv":
Load 1 ASDF system:
cl-csv
; Loading "cl-csv"
...
(:CL-CSV)
的CL-CSV分割你的列表的列表文件讓我們使用CSV文件從here稱爲train.csv是一個正常的CSV文件:
PassengerId,Survived,Pclass,Name,Sex,Age,SibSp,Parch,Ticket,Fare,Cabin,Embarked
1,0,3,"Braund, Mr. Owen Harris",male,22,1,0,A/5 21171,7.25,,S
2,1,1,"Cumings, Mrs. John Bradley (Florence Briggs Thayer)",female,38,1,0,PC 17599,71.2833,C85,C
3,1,3,"Heikkinen, Miss. Laina",female,26,0,0,STON/O2. 3101282,7.925,,S
4,1,1,"Futrelle, Mrs. Jacques Heath (Lily May Peel)",female,35,1,0,113803,53.1,C123,S
5,0,3,"Allen, Mr. William Henry",male,35,0,0,373450,8.05,,S
6,0,3,"Moran, Mr. James",male,,0,0,330877,8.4583,,Q
7,0,1,"McCarthy, Mr. Timothy J",male,54,0,0,17463,51.8625,E46,S
8,0,3,"Palsson, Master. Gosta Leonard",male,2,3,1,349909,21.075,,S
9,1,3,"Johnson, Mrs. Oscar W (Elisabeth Vilhelmina Berg)",female,27,0,2,347742,11.1333,,S
10,1,2,"Nasser, Mrs. Nicholas (Adele Achem)",female,14,1,0,237736,30.0708,,C
11,1,3,"Sandstrom, Miss. Marguerite Rut",female,4,1,1,PP 9549,16.7,G6,S
12,1,1,"Bonnell, Miss. Elizabeth",female,58,0,0,113783,26.55,C103,S
13,0,3,"Saundercock, Mr. William Henry",male,20,0,0,A/5. 2151,8.05,,S
...
...
的CL-CSV加載它列出每個行的目錄是:
CL-USER> (cl-csv:read-csv #P"./train.csv")
(("PassengerId" "Survived" "Pclass" "Name" "Sex" "Age" "SibSp" "Parch" "Ticket"
"Fare" "Cabin" "Embarked")
("1" "0" "3" "Braund, Mr. Owen Harris" "male" "22" "1" "0" "A/5 21171" "7.25"
"" "S")
("2" "1" "1" "Cumings, Mrs. John Bradley (Florence Briggs Thayer)" "female"
"38" "1" "0" "PC 17599" "71.2833" "C85" "C")
("3" "1" "3" "Heikkinen, Miss. Laina" "female" "26" "0" "0" "STON/O2. 3101282"
"7.925" "" "S")
("4" "1" "1" "Futrelle, Mrs. Jacques Heath (Lily May Peel)" "female" "35" "1"
"0" "113803" "53.1" "C123" "S")
("5" "0" "3" "Allen, Mr. William Henry" "male" "35" "0" "0" "373450" "8.05" ""
"S")
("6" "0" "3" "Moran, Mr. James" "male" "" "0" "0" "330877" "8.4583" "" "Q")
("7" "0" "1" "McCarthy, Mr. Timothy J" "male" "54" "0" "0" "17463" "51.8625"
"E46" "S")
("8" "0" "3" "Palsson, Master. Gosta Leonard" "male" "2" "3" "1" "349909"
"21.075" "" "S")
然後打印它只是使用的格式功能,這是打印清單的小動作和每個列表的分隔符,我用零來代替噸得到一個字符串,但你可以用t打印,所以這是在lisp中得到這個的一行代碼,我使用新的行分隔符作爲列表的第一級(然後是行),然後是項目的「,」行:
CL-USER> (format nil "~{~{~a, ~}~% ~}" (cl-csv:read-csv #P"train.csv"))
"PassengerId, Survived, Pclass, Name, Sex, Age, SibSp, Parch, Ticket, Fare, Cabin, Embarked,
1, 0, 3, Braund, Mr. Owen Harris, male, 22, 1, 0, A/5 21171, 7.25, , S,
2, 1, 1, Cumings, Mrs. John Bradley (Florence Briggs Thayer), female, 38, 1, 0, PC 17599, 71.2833, C85, C,
3, 1, 3, Heikkinen, Miss. Laina, female, 26, 0, 0, STON/O2. 3101282, 7.925, , S,
4, 1, 1, Futrelle, Mrs. Jacques Heath (Lily May Peel), female, 35, 1, 0, 113803, 53.1, C123, S,
5, 0, 3, Allen, Mr. William Henry, male, 35, 0, 0, 373450, 8.05, , S,
6, 0, 3, Moran, Mr. James, male, , 0, 0, 330877, 8.4583, , Q,
7, 0, 1, McCarthy, Mr. Timothy J, male, 54, 0, 0, 17463, 51.8625, E46, S,
8, 0, 3, Palsson, Master. Gosta Leonard, male, 2, 3, 1, 349909, 21.075, , S,
9, 1, 3, Johnson, Mrs. Oscar W (Elisabeth Vilhelmina Berg), female, 27, 0, 2, 347742, 11.1333, , S,
10, 1, 2, Nasser, Mrs. Nicholas (Adele Achem), female, 14, 1, 0, 237736, 30.0708, , C,
11, 1, 3, Sandstrom, Miss. Marguerite Rut, female, 4, 1, 1, PP 9549, 16.7, G6, S,
12, 1, 1, Bonnell, Miss. Elizabeth, female, 58, 0, 0, 113783, 26.55, C103, S,
13, 0, 3, Saundercock, Mr. William Henry, male, 20, 0, 0, A/5. 2151, 8.05, , S,
14, 0, 3, Andersson, Mr. Anders Johan, male, 39, 1, 5, 347082, 31.275, , S,
15, 0, 3, Vestrom, Miss. Hulda Amanda Adolfina, female, 14, 0, 0, 350406, 7.8542, , S,
16, 1, 2, Hewlett, Mrs. (Mary D Kingcome) , female, 55, 0, 0, 248706, 16, , S,
17, 0, 3, Rice, Master. Eugene, male, 2, 4, 1, 382652, 29.125, , Q,
18, 1, 2, Williams, Mr. Charles Eugene, male, , 0, 0, 244373, 13, , S,
19, 0, 3, Vander Planke, Mrs. Julius (Emelia Maria Vandemoortele), female, 31, 1, 0, 345763, 18, , S,
我希望這有助於
最簡單的方法是使用現有的庫。 [cl-csv](https://github.com/AccelerationNet/cl-csv)似乎有一個將文件讀入列表清單的功能。 – jkiiski
您正試圖轉換Python代碼?到目前爲止,你有什麼? –
我不能像Python代碼那樣簡單。 – rnso