Python Exercise: Generate a list and tuple with comma-separated numbers


(Python Example for Citizen Data Scientist & Business Analyst)


Write a Python program which accepts a sequence of comma-separated numbers from user and generate a list and a tuple with those numbers.

Sample data: 3, 5, 7, 23

Python list:

A list is a container which holds comma separated values (items or elements) between square brackets where items or elements need not all have the same type. In general, we can define a list as an object that contains multiple data items (elements). The contents of a list can be changed during program execution. The size of a list can also change during execution, as elements are added or removed from it.

Python tuple:

A tuple is container which holds a series of comma separated values (items or elements) between parentheses such as an (x, y) co-ordinate. Tuples are like lists, except they are immutable (i.e. you cannot change its content once created) and can hold mix data types.

Sample Solution:-

Python Code:

values = input("Input some comma seprated numbers : ")
list = values.split(",")
tuple = tuple(list)
print('List : ',list)
print('Tuple : ',tuple)
Sample Output:
Input some comma seprated numbers : 3,5,7,23                       
List :  ['3', '5', '7', '23']                                      
Tuple :  ('3', '5', '7', '23')



Generate a list and tuple with comma-separated numbers


Sign up to get end-to-end “Learn By Coding” example.



Applied Machine Learning & Data Science with Python, R and SQL.

A list of Python, R and MATLAB Codes for Applied Machine Learning and Data Science


Subscribe to our YouTube channel and press the ring to get latest update on Python and R coding recipesCoding is our strength.


Learn by Coding Categories:


Data Analytics:

Data Science:

Data Visualisation:

Machine Learning Recipe:




Supervised Learning:

Tabular Data Analytics:

End-to-End Data Science Recipes:

Applied Statistics:

Bagging Ensemble:

Boosting Ensemble:



Data Analytics:

Data Science:

Data Visualisation:

Decision Tree:


Machine Learning Recipe:

Multi-Class Classification:

Neural Networks:

Python Machine Learning:

Python Machine Learning Crash Course:

R Classification:

R for Beginners:

R for Business Analytics:

R for Data Science:

R for Data Visualisation:

R for Excel Users:

R Machine Learning:

R Machine Learning Crash Course:

R Regression:



Excel examples for beginners:

C Programming tutorials & examples:

Javascript tutorials & examples:

Python tutorials & examples:

R tutorials & examples:

SQL tutorials & examples:

SQL for Beginners in 2 Weeks:


Portfolio Projects for Aspiring Data Scientists: Tabular Text & Image Data Analytics as well as Time Series Forecasting in Python & R @



Disclaimer: The information and code presented within this recipe/tutorial is only for educational and coaching purposes for beginners and developers. Anyone can practice and apply the recipe/tutorial presented here, but the reader is taking full responsibility for his/her actions. The author (content curator) of this recipe (code / program) has made every effort to ensure the accuracy of the information was correct at time of publication. The author (content curator) does not assume and hereby disclaims any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from accident, negligence, or any other cause. The information presented here could also be found in public knowledge domains.