Sometimes while working in Python we can have a problem in which we need to restrict the data elements to be just of one type. List, can be heterogeneous, can have data of multiple data types and it is sometimes undesirable. There a need to convert this to data structure which restricts the type of data. The Python language comes with array data structure which can be used for this purpose. Let’s discuss a way to convert list to array.
Method : Using
array() + data type indicator
This task can be easily performed using
array(). This is an inbuilt function in Python to convert to array. The data type indicator “i” is used in case of integers, which restricts data type.
The original list : [6, 4, 8, 9, 10] List after conversion to array : array('i', [6, 4, 8, 9, 10])
- Python | Convert an array to an ordinary list with the same items
- Python | Convert mixed data types tuple list to string list
- Python | Convert string List to Nested Character List
- Python | Convert list of numerical string to list of Integers
- Python Program to convert List of Integer to List of String
- Python | Convert list of string into sorted list of integer
- Python - Convert list of dictionaries to Dictionary Value list
- Python | Convert List of lists to list of Strings
- Python | Convert 1D list to 2D list of variable length
- Python - Convert Value list elements to List records
- Python | Convert List of Dictionary to Tuple list
- Python | Convert Integral list to tuple list
- Python | Convert list to indexed tuple list
- Python - Convert List to key-value list by prefix grouping
- Python | Convert a string representation of list into list
- Python | Convert list of tuples to list of strings
- Python | Convert string enclosed list to list
- Python - Convert Tuple value list to List of tuples
- Python | Convert a nested list into a flat list
- Python - Convert List of Dictionaries to List of Lists
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.