By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,285 Members | 1,659 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,285 IT Pros & Developers. It's quick & easy.

Conjunction List

P: n/a
http://codepad.org/MV3k10AU

I want to write like next one.

def conjunction(number=a[1],name=b[1],size=c[1]):
flag = a[0]==b[0]==c[0]
if flag:
for e in zip(number,name,size):
print e

conjunction(a,b,c)

-----------------------------------------------------------------------------------------------------
function args receive sequence element:

def somefunc(name=elm1[1], size=elm2[1], color=elm3[1]):
for e in zip(name, size, color):
print e,

conjunction(a,b,c)
-----------------------------------------------------------------------------------------------------

not like two case:
-----------------------------------------------------------------------------------------------------

def somefunc(elm1, elm2, elm3):
name = elm1[1]; size = elm1[1]; color = elm1[1] # best solution?
for e in zip(name, size, color):
print e,

conjunction(a,b,c)
-----------------------------------------------------------------------------------------------------

def somefunc(elm1, elm2, elm3, **attr):
for e in zip(attr['name'], attr['size'], attr['color']):
print e,

conjunction(a,b,c, name=a[1], size=b[1], color=c[1]) # many args...
-----------------------------------------------------------------------------------------------------

What's a good approach to get the conjunction nest-list-data?
Jun 1 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On May 31, 8:01 pm, ccy56...@gmail.com wrote:
http://codepad.org/MV3k10AU

I want to write like next one.

def conjunction(number=a[1],name=b[1],size=c[1]):
flag = a[0]==b[0]==c[0]
if flag:
for e in zip(number,name,size):
print e

conjunction(a,b,c)

-----------------------------------------------------------------------------------------------------
function args receive sequence element:

def somefunc(name=elm1[1], size=elm2[1], color=elm3[1]):
for e in zip(name, size, color):
print e,

conjunction(a,b,c)
-----------------------------------------------------------------------------------------------------

not like two case:
-----------------------------------------------------------------------------------------------------

def somefunc(elm1, elm2, elm3):
name = elm1[1]; size = elm1[1]; color = elm1[1] # best solution?
for e in zip(name, size, color):
print e,

conjunction(a,b,c)
-----------------------------------------------------------------------------------------------------

def somefunc(elm1, elm2, elm3, **attr):
for e in zip(attr['name'], attr['size'], attr['color']):
print e,

conjunction(a,b,c, name=a[1], size=b[1], color=c[1]) # many args...
-----------------------------------------------------------------------------------------------------

What's a good approach to get the conjunction nest-list-data?
The one you comment with "best solution?" is ok for this example. If
you dislike the repetitive part of setting the flag and getting the
second element of each argument, or especially if you want to
generalize it to more than three arguments, here's one way to do it:

def conjunction(*args):
if not args: return
first = args[0][0]
if all(arg[0]==first for arg in args):
for e in zip(*(arg[1] for arg in args)):
print e
>>conjuction(a,b,c)
('0', 'one', '0%')
('1', 'two', '50%')
('2', 'three', '100%')

HTH,
George
Jun 1 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.