How do I convert between tuples and lists?
2011-11-22 20:31
316 查看
The function tuple(seq) converts any sequence (actually, any iterable) into a tuple with the same items in the same order.
For example, tuple([1, 2, 3]) yields (1, 2, 3) and tuple('abc') yields ('a', 'b', 'c'). If the argument is a tuple, it does not make a copy but returns the same object, so it is cheap to call tuple() when you aren't sure that an object is already a tuple.
The function list(seq) converts any sequence or iterable into a list with the same items in the same order. For example, list((1, 2, 3)) yields [1, 2, 3] and list('abc') yields ['a', 'b', 'c']. If the argument is a list, it makes a copy just like seq[:] would.Source [http://pyfaq.infogami.com/how-do-i-convert-between-tuples-and-lists]
相关文章推荐
- How do I convert between tuples and lists?
- C++ String: How to convert between 'CString' and 'std::string'?
- How To Convert Virtual Machines Between VirtualBox and VMware[测试可行]
- Difference Between List and Tuples
- iPhone开发:如何阻止文件被iTunes和iCloud同步 How do I prevent files from being backed up to iCloud and iTunes?
- pes and ts stream, how to convert
- [Java] Convert Between the Two, String[] and ArrayList<String>
- DER vs. CRT vs. CER vs. PEM Certificates and How To Convert Them
- Convert Between Class And Xml
- How&nbsp;do&nbsp;I&nbsp;get&nbsp;default&nbsp;date&nbsp;and&nbsp;ti…
- Objective C SEl 和@selector是怎么工作的||How do SEL and @selector work in iphone sdk?
- 3 ways to do WCF Concurrency Management(Single, Multiple, and Reentrant and How to do with Throttling)
- How-to: Do Statistical Analysis with Impala and R
- How to do the job effectively and excellently
- How do I quickly switch between workspaces in unity? up vote 41 down vote favorite 8 I'm using U
- How to use Connector to sync data between AX and CRM
- What is Logical Volume Management and How Do You Enable It in Ubuntu?
- convert between PIL Image and ndarray
- How do I get dynamic DataSources with iBATIS and Spring?
- How To Pass Arrays Between Visual Basic and C