Click here to Skip to main content
13,632,371 members
Rate this:
 
Please Sign up or sign in to vote.
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 15-Mar-17 5:54am
Updated 15-Mar-17 8:00am
Comments
Richard MacCutchan 15-Mar-17 12:09pm
   
What do you mean "its not what i need"?
15-Mar-17 12:16pm
   
Thank you i got the wright answer using tuple function...

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01-2016 | 2.8.180712.1 | Last Updated 15 Mar 2017
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100