pythonic « tuple « Python Data Type Q&A

Home
Python Data Type Q&A
1.array
2.date
3.dictionary
4.Format
5.integer
6.List
7.numpy
8.regex
9.string
10.tuple
Python Data Type Q&A » tuple » pythonic 

1. pythonic way to explode a list of tuples    stackoverflow.com

I need to do the opposite of this http://stackoverflow.com/questions/756550/multiple-tuple-to-two-pair-tuple-in-python Namely, I have a list of tuples

[(1,2), (3,4), (5,6)]
and need to produce this
[1,2,3,4,5,6]
I would personally do this
>>> tot = []
>>> for i in ...

2. What is a Pythonic way to get a list of tuples of all the possible combinations of the elements of two lists?    stackoverflow.com

Suppose I have two differently-sized lists

a = [1, 2, 3]
b = ['a', 'b']
What is a Pythonic way to get a list of tuples c of all the possible combinations of one ...

3. How to create a list or tuple of empty lists in Python?    stackoverflow.com

I need to incrementally fill a list or a tuple of lists. Something that looks like this:

result = []
firstTime = True
for i in range(x):
    for j in someListOfElements:
 ...

4. How do I convert tuple of tuples to list in one line (pythonic)?    stackoverflow.com

query = 'select mydata from mytable'
cursor.execute(query)
myoutput = cursor.fetchall() 
print myoutput

(('aa',), ('bb',), ('cc',))
Why is it (cursor.fetchall) returning a tuple of tuples instead of a tuple since my query is asking for only ...

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.