0
Making words with items in lists.
How we can unite items in two different lists with “for” block. For example: list_1 = ["fo", "bea", "umb"] list_2 = ["ur", "utiful", "rella"] # result list should look like this > # result_list = ["four", "beautiful", "umbrella"] result_list = [] . . . ?
18 Answers
+ 6
What have you tried?
+ 6
YAKUP KARAKAŞ and don't let this make you hesitate from asking, we're all here to learn (:
Just please try to include your attempt next time even if it's wrong so we (the community) can help you fix it. Good luck!
+ 5
YAKUP KARAKAŞ not to be mean, but as someone (you) who has finished Python course on SoloLearn, you shouldn't even be thinking about something as easy as this.
I think it is better for you to restart the course and practice everything before moving on to the next lesson.
Anyway, to answer, Vadivelan already posted the for-loop method. If you want to use the zip method, this is how:
result = [i+j for (i, j) in zip(list_1, list_2)]
+ 5
Nathan Sikati your code won't work without zip(), it will return ValueError
+ 3
Aymane Boukrouh
It is great to hear this :) thank you all for everything you are doing in here :) and I understood the point that you are telling me.
+ 2
My suggestion:
Use append function
+ 1
Vadivelan I did. but giving unnecessary result.
result_list = []
for x in list_1:
for y in list_2:
result_list.append(x+y)
print(result_list)
+ 1
result_list =[]
for i in range(0,len(list_1)):
result_list.append(list_1[i]+list_2[i])
print(result_list)
+ 1
result_list=[]
for i in range(len(list_1)):
result_list.append(list_1[i]+list_2[i])
print(result_list)
+ 1
Aymane Boukrouh thanks. I’m already working on that restarted course :)
+ 1
You can just use the join() function like this.
Separator.join(list)
So if you want your words be seperated by space, just do
" ".join(list)
+ 1
Before you must have your result list by doing
for i, j in (list1, list2):
Result_list.append(i+j)
+ 1
list_1 = ["fo", "bea", "umb"]
list_2 = ["ur", "utiful", "rella"]
list_3=list_2
for j in range(0,3) :
list_3[j]=list_1[j]+list_2[j]
print(list_3[j])
0
Aymane Boukrouh I have tried this
result_list = list(zip(list_1, list_2))
but didn’t work. and I will try with for cycle too.
0
Roy thank you my friend
0
Vadivelan thank you so much :)
0
For j in rang (1,3):
List_3=List_1[j]+list_2[j]