Write a python program to merge nested lists ?
Program
def myfun():
nested_list = [[2, 4, 6],[8, 10, 12, 14]]
new_list = sum(nested_list,[])
print(new_list)
if __name__=="__main__":
myfun()
Output:
[2, 4, 6, 8, 10, 12, 14]
Using reduce function
from functools import reduce
def myfun():
nested_list = [[2, 4, 6],[8, 10, 12, 14]]
new_list = reduce(lambda x, y: x+y, nested_list)
print(new_list)
if __name__=="__main__":
myfun()
Output:
[2, 4, 6, 8, 10, 12, 14]
More Questions
54 . Write a python program to checking if a string is empty or not ?
55 . Write a python program to merge nested lists ?
56 . Write a python program to Checking if a File Exists or Not ?
57 . Write a python program to convert uppercase strings and we want to convert them into lowercase strings and remove duplicates ?
58 . Write a python program to display list of numbers and we want to return all the numbers from the list that are divisible by 2 and remove duplicates at the same time.
59 . Write a python program to calculate average using python *args ?
60 . Write a Python program to find the area of a triangle.
61 . Write a Python program to convert kilometers to miles.
62 . Write a Python program to convert Celsius to Fahrenheit.
63 . Write a Python Program to Check if a Number is Positive, Negative or Zero.
64 . Write a Python Program to Check if a Number is Odd or Even.
For latest job updates join Telegram Channel: https://t.me/sateeshm