在劊子手遊戲我提出,我有一個包含一個文本文件,這樣的:從文件中獲取列表?
[
[
['microsoft windows','common operating system',1],
['apple ios,a useless operating system',1],
['chromeos','a very simple OS developed by chrome',1],
["linux","the most accesable and custimizable OS",1]
],
[
["photoshop", "the most popular image editting program",2],
["adobe flash","basic animating and programming program",2],
["pineapple","a spikey sweet fruit",2],
["chrome", "a web browser",2]
],
[
["gpu","a computers _____ proccesing unit", 3],
["tree", "a large plant found every where",3],
["kangaroo","a marsupial found in the outback",3],
["hawiian pizza","a very disputed type of triangular food",3]
],
[
["negev","a light machine gun, from csgo", 4],
["revolver","a high caliber hand canon", 4],
["desert eagle", "a infamous hand canon, highly praised in the USA", 4],
["karambit knife","a blade shaped like a claw, know as very deadly", 4]
]
]
因此,使用文件IO,我寫了這個:
f = open('words.py')
lines = f.readlines()
for line in lines:
cat1.append(line)
print(cat1)
但我得到的是:
['[\n', '[\n', "['microsoft windows','common operating system',1],\n", "['apple ios,a useless operating system',1],\n", "['chromeos','a very simple OS developed by chrome',1],\n", '["linux","the most accesable and custimizable OS",1]\n', '],\n', '[\n', '["photoshop", "the most popular image editting program",2],\n', '["adobe flash","basic animating and programming program",2],\n', '["pineapple","a spikey sweet fruit",2],\n', '["chrome", "a web browser",2]\n', '],\n', '[\n', '["gpu","a computers _____ proccesing unit", 3],\n', '["tree", "a large plant found every where",3],\n', '["kangaroo","a marsupial found in the outback",3],\n', '["hawiian pizza","a very disputed type of triangular food",3]\n', '],\n', '[\n', '["negev","a light machine gun, from csgo", 4],\n', '["revolver","a high caliber hand canon", 4],\n', '["desert eagle", "a infamous hand canon, highly praised in the USA", 4],\n', '["karambit knife","a blade shaped like a claw, know as very deadly", 4]\n', ']\n', ']\n']
我該如何將它劃分爲4個子組,其中也包含4個子列表,最後我如何刪除'\n'
?