![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can I convert a Python tuple to an Array?
To convert a tuple to an array(list) you can directly use the list constructor.
example
x = (1, 2, 3) y = list(x) print(y)
Output
This will give the output −
[1, 2, 3]
Example
If you have a multi-level tuple and want a flat array, you can use the following −
z = ((1, 2, 3), (4, 5)) y = [a for b in z for a in b] print(y)
Output
This will give the output −
[1, 2, 3, 4, 5]
Advertisements