In: Computer Science
Please use Python for both
Concatenate List Elements
Write a function called concat_list that accepts a list of strings as an argument and returns a string made up of all elements in the list concatenated together in order. For example, if the argument is ['one', 'two', 'three'], the return value would be 'onetwothree'.
Remove List Duplicates
Write a function called remove_duplicates that accepts a list and returns a list containing the same elements in the same order but with duplicates removed. For example, if the argument is [7, 4, 2, 7, 2, 2, 9, 4], the returned list would be [7, 4, 2, 9].
1).
Code Explanation:
Code:
def concat_list(x):
s = ""
for i in x:
s = s+i
return s
x = ['one', 'two', 'three']
res = concat_list(x)
print(res)
O/P:
onetwothree
Code screenshot:
O/P screenshot:
2).
Code Explanation:
Code Explanation:
Code:
def remove_duplicates(x):
temp = []
for i in x:
if i not in temp:
temp.append(i)
return temp
x = [7,4,2,7,2,2,9,4]
res = remove_duplicates(x)
print(res)
O/P:
[7, 4, 2, 9]
Code screenshot:
O/P screenshot:
(If you still have any doubts regarding this answer please comment)