Making words with items in lists. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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 = [] . . . ?

1st Sep 2020, 4:15 PM
YAKUP KARAKAŞ
YAKUP KARAKAŞ - avatar
18 Answers
+ 6
What have you tried?
1st Sep 2020, 4:25 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 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!
1st Sep 2020, 4:46 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 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)]
1st Sep 2020, 4:35 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 5
Nathan Sikati your code won't work without zip(), it will return ValueError
1st Sep 2020, 6:46 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 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.
1st Sep 2020, 4:48 PM
YAKUP KARAKAŞ
YAKUP KARAKAŞ - avatar
+ 2
My suggestion: Use append function
1st Sep 2020, 4:33 PM
Vadivelan
+ 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)
1st Sep 2020, 4:37 PM
YAKUP KARAKAŞ
YAKUP KARAKAŞ - avatar
+ 1
result_list =[] for i in range(0,len(list_1)): result_list.append(list_1[i]+list_2[i]) print(result_list)
1st Sep 2020, 4:39 PM
Vadivelan
+ 1
result_list=[] for i in range(len(list_1)): result_list.append(list_1[i]+list_2[i]) print(result_list)
1st Sep 2020, 4:43 PM
Roy
Roy - avatar
+ 1
Aymane Boukrouh thanks. I’m already working on that restarted course :)
1st Sep 2020, 4:43 PM
YAKUP KARAKAŞ
YAKUP KARAKAŞ - avatar
+ 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)
1st Sep 2020, 6:30 PM
Nathan Sikati
Nathan Sikati - avatar
+ 1
Before you must have your result list by doing for i, j in (list1, list2): Result_list.append(i+j)
1st Sep 2020, 6:44 PM
Nathan Sikati
Nathan Sikati - avatar
1st Sep 2020, 7:02 PM
Nathan Sikati
Nathan Sikati - avatar
+ 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])
3rd Sep 2020, 6:33 AM
Manssour Nedjar
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.
1st Sep 2020, 4:31 PM
YAKUP KARAKAŞ
YAKUP KARAKAŞ - avatar
0
Roy thank you my friend
1st Sep 2020, 4:51 PM
YAKUP KARAKAŞ
YAKUP KARAKAŞ - avatar
0
Vadivelan thank you so much :)
1st Sep 2020, 4:51 PM
YAKUP KARAKAŞ
YAKUP KARAKAŞ - avatar
0
For j in rang (1,3): List_3=List_1[j]+list_2[j]
3rd Sep 2020, 6:23 AM
Manssour Nedjar