多个组合数组中字符串的所有元素

时间:2017-12-10 21:56:28

标签: arrays python-3.x list csv join

现在我在加入表中的每个元素时遇到问题(参见下图)

这是我的代码:

[robiłem]
[robiłam]
[robiło]
[marudziłem]
[marudziłam]
[marudziło]
[biegałem]
[biegałam]
[biegało]

我想输出:

<div  id="WebPartWPQ6_ChromeTitle">
<a accesskey="W" href="/siteurl" >
<span>Access </span></a></div>

可以使用1方法调用 - 例如:string.join()?

join every element

1 个答案:

答案 0 :(得分:0)

这是metod字符串连接的问题。这是正确的代码:

import csv
import string

def remove_cruft(s):
    return s[:-1]

def add_cruft(s):
    return s


with open('name.csv', 'r') as f:
    reader = csv.reader(f)
    my_list = [[remove_cruft(item) for item in line] for line in reader]
    #my_list_2 = [[remove_cruft(item) for item in line] for line in reader]
    my_list2 = [[add_cruft(item) for item in line] for line in reader]

print(my_list2)

my_list==my_list2

for i in my_list:
    temp=i[0]
    title = "Czas przeszły: "
    i[0] =title + temp + 'lem'
    i.append(temp + 'lam')
    i.append(temp + 'lo')

for i1 in my_list2:
    temp1=i[0]
    title1 = "Czas przeszły:     "
    i[0] =title1 + temp1 + 'laaem'
    i.append(temp1 + 'laaam')
    i.append(temp1 + 'lsso')

print(my_list)
print(my_list2)

with open('output1.csv','w') as output:

    writer = csv.writer(output)
    for val in my_list:
      writer.writerow([val])

THX for Answer! :)