如何在for循环python中动态更改变量名?

时间:2015-08-25 14:23:55

标签: python loops iteration

我有这样的代码。不知何故,我使用for循环简化了它。

cd

我想使用for循环让它像这样工作

if set(u) & set(s1):
    u = u-s1
    print('s1')    
if set(u) & set(s2):
    u = u-s2
    print('s2')    
if set(u) & set(s3):
    u = u-s3
    print('s3')    
if set(u) & set(s4):
    u = u-s4
    print('s4')    
if set(u) & set(s5):
    u = u-s5
    print('s5')    
if set(u) & set(s6):
    u = u-s6
    print('s6')

1 个答案:

答案 0 :(得分:0)

这样做你想要的吗?

select 
    b.PortID,
    max(endversion) as EndVersion,
    d.ShortName as RuleName 
from xr.ObjectPropertyValue a 
join moxyportfolio b 
    on a.objectid = b.portkey 
join xr.AssignAllObjectsRule c 
    on a.Objectclassid = c.ObjectClassID -- can replace with xr.assignobjectrule if it's rule is not assigned to all portfolios.
join xr.rulebase d 
    on c.RuleID = d.RuleID 
group by a.ObjectId, b.portid, d.ShortName
having sum(case when endversion is null then 1 else 0 end) = 0