'Merging two lists into one
starting arrays
listone[1,2,3,4,5]
listtwo[a,b,c,d,e]
wanted outcome
[1a,2b,3c,4d,5e]
My Attempt
filename = open('Forks.csv', 'r')
file = csv.DictReader(filename)
Item = []
Price = []
Full = []
for col in file:
Item.append(col['Item Name'])
Price.append(col['Price'])
for n in Item and Price:
Full_Var = (n[Item],':', '£', n[Price])
Full.append(Full_Var)
It's from a csv file with two columbs (Item_Name and Price)
Solution 1:[1]
You can easily merge two lists like this:
list_one = [1, 2, 3, 4, 5]
list_two = ["a", "b", "c", "d", "e"]
merged_list = []
for i, j in zip(list_one, list_two):
merged_list.append(str(i) + str(j))
print(merged_list)
Solution 2:[2]
here is the solution for merging two list.
l1 = [1,2,3,4]
l2 = ['a','b','c','d']
res = []
for i in range(len(l1)):
res.append(str(l1[i])+l2[i])
print(res)
Thanks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | vate |
| Solution 2 | anonymous |
