Created
July 25, 2022 14:26
-
-
Save Codehunter-py/af5b8896d5d3d30b9f4bae757ab36e9f to your computer and use it in GitHub Desktop.
Given a 2D list, write a Python program to convert the given list into a flattened list.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy | |
list_2d = [['Volkswagen', 'Mercedes', 'BMW'], ['Honda', 'Toyota', 'Mazda']] | |
def convertList(list_2d): | |
return list(numpy.concatenate(list_2d).flat) | |
print(convertList(list_2d)) # Output ['Volkswagen', 'Mercedes', 'BMW', 'Honda', 'Toyota', 'Mazda'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment