Click here to Skip to main content
15,943,729 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hello i have one question how to convert A=['a','b','c','d']
to A=('a','b','c','d')

What I have tried:

i used tolist function but its not what i need
Posted
Updated 15-Mar-17 8:00am
Comments
Richard MacCutchan 15-Mar-17 12:09pm    
What do you mean "its not what i need"?
Member 11436383 15-Mar-17 12:16pm    
Thank you i got the wright answer using tuple function...

1 solution

You are confused.
This
['a','b','c','d'] 
is already a python list
This
('a','b','c','d')
is a python tuple
To convert from a list to a tuple, try this:
#This is a list
python_list=['a','b','c','d'] 
print(python_list)

python_tuple = tuple(python_list)
#This is a tuple
print(python_tuple)
and you get
['a', 'b', 'c', 'd']
('a', 'b', 'c', 'd')
In fact, to convert to and forth between list and tuple, use
list(python_tuple)
and
tuple(python_list)
respectively.
 
Share this answer
 
v2
Comments
Bryian Tan 15-Mar-17 19:03pm    
Good stuff Sir. I learn something new. +5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900