作者busystudent (busystudent)
看板Python
标题[问题] 关於list的append问题
时间Sat Apr 9 17:31:08 2016
hi 这几天写程式,有几个关於list apeend的问题要跟大家请教。
1. 我写了一个for回圈,可以print 很多list,例如以下程式码
for shop_link in shop_table:
. ....
print shop_link
output:
['leerentveld', 'mohell', 'vinoph', ]
['mdefelice', 'iamthemomo', 'tvenchus', ]
我该如和变成以下的name_list呢?这种把两种list内的值合起来
name_ist = ['leerentveld', 'mohell', 'vinoph', 'mdefelice', 'iamthemomo', 'tvenchus',]
name_ist = ['leerentveld', 'mohell', 'vinoph', 'mdefelice', 'iamthemomo', 'tvenchus',]
我第一种尝试为
name_list= []
for shop_link in shop_table:
. ....
print shop_link
name_list.append(shop_link)
output:
[ ['leerentveld', 'mohell', 'vinoph', ],
['mdefelice', 'iamthemomo', 'tvenchus', ] ]
我打算使用append的方式一个个加入,可是输出却不是我想要的,变成[[ ],[ ]]了请问我该如何修改
--
Sent from my Windows
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 1.172.97.181
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 1.172.97.181
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1460194271.A.728.html
※ 编辑: busystudent (223.140.224.116), 04/09/2016 17:37:29
1F:推 aweimeow: namelist = namelist + shop_link 04/09 17:41
2F:→ aweimeow: 因为你的 shop_link 也是 list 所以不能这样 append 04/09 17:43
3F:→ busystudent: 谢谢 我想我对append真的不熟悉 04/09 17:54
4F:→ freeunixer: 不是有 extend 可以用.............................. 04/09 19:19
5F:推 aweimeow: 楼上大大学习了 <(_ _)> 我不知道有这东西 04/09 20:42
6F:→ freeunixer: .................................................. 04/09 21:10
7F:→ freeunixer: 还是找本书把 type.func 看一次,或至少 help(type) 吧 04/09 21:11
8F:推 largesperm: 用英文去 google 再破也可以 python list plus 04/09 21:17
9F:→ largesperm: 通常 stackvoerflow 都会有东西 04/09 21:17
10F:→ largesperm: stackoverflow 很多怪问题都有解答 04/09 21:18
11F:→ busystudent: 谢谢大家的回覆 04/09 21:33
12F:→ MOONY135: 你要去搞懂list在做啥 append是以加一个元素进来 04/10 08:31
13F:→ MOONY135: 当然一个LIST本身也可以当成一个元素了 04/10 08:32