Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3b9a1d7

Browse files
Add files via upload
1 parent 3d9b4cd commit 3b9a1d7

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

‎Merge list form sentence.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import itertools
2+
3+
def merge_list(list1, list2):
4+
merged_data=""
5+
6+
l1 = len(list1)
7+
l2 = len(list2)
8+
9+
for i, j in zip(range(0,len(list1)),range(len(list1)-1,-1,-1)):
10+
a = list1[i]
11+
b = list2[j]
12+
if a is None:
13+
a = ""
14+
if b is None:
15+
b = ""
16+
17+
merged_data += a + b + " "
18+
19+
return merged_data.strip()
20+
21+
#Provide different values for the variables and test your program
22+
list1=['A', 'app','a', 'd', 'ke', 'th', 'doc', 'awa']
23+
list2=['y','tor','e','eps','ay',None,'le','n']
24+
merged_data=merge_list(list1,list2)
25+
print(merged_data)
26+
27+
28+
29+
30+
31+
32+
# Question
33+
# Submission
34+
# Given two lists, both having String elements, write a python program using python lists to create a new string as per the rule given below:
35+
# The first element in list1 should be merged with last element in list2, second element in list1 should be merged with second last element in list2 and so on. If an element in list1/list2 is None, then the corresponding element in the other list should be kept as it is in the merged list.
36+
37+
# Sample Input Expected Output
38+
# list1=['A', 'app','a', 'd', 'ke', 'th', 'doc', 'awa']
39+
# list2=['y','tor','e','eps','ay',None,'le','n'] "An apple a day keeps the doctor away"

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /