展开全部
def fn_nm(num, div, flag):
return flag if num % div == 0 else ''
for i in xrange(1, 101):
print i , '*' join(filter(None, [
fn_nm(i, 3, 'A'),
fn_nm(i, 5, 'B')
]))
orlst = range(101)
da = dict(zip(lst[::3], "A"*100))
db = dict(zip(lst[::5], "B"*100))
def merge(*a):
return "*".join(filter(None, a))
for i in lst[1:]:
print i, merge(da.get(i), db.get(i))
and 更进一步e68a843231313335323631343130323136353331333332643266:lst = range(101)
def merge(*a):
return "*".join(filter(None, a))
for i in lst[1:]:
print i, merge(*map(lambda x: x.get(i), [
dict(zip(lst[::3], "A"*100)),
dict(zip(lst[::5], "B"*100)),
dict(zip(lst[::7], "C"*100)),
]))