删除Python列表括号 [英] Python List Bracket Removal

查看:419
本文介绍了删除Python列表括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我试图将CSV文件中的股票代码列表添加到python列表中.

So I am trying to add a list of ticker symbols from a CSV file into a python list.

CSV文件如下所示:

The CSV File looks like this:

AAPL
XOM
EMC

使用stockList []时.如何删除['']括号和引号?

When working with the stockList[]. How do I remove the [' '] brackets and quote marks?

我的代码如下:

stockList = []
csvReader = csv.reader(open('tickers.csv','rb'), quoting=csv.QUOTE_NONE)
for row in csvReader:
    stockList.append(row)

for item in stockList:
    print repr(item)

例如,当上面的代码运行时,它输出:

For example when the code above is ran it outputs:

['AAPL']
['XOM']
['EMC']

推荐答案

看起来CSVReader正在返回行列表.以这种方式修改您的代码.

It looks like CSVReader is returning a list of rows. Modify your code in this way.

for row in csvReader:
    row = "".join(row)
    stockList.append(row)

这篇关于删除Python列表括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆