439,942 Members | 1,788 Online
Need help? Post your question and get tips & solutions from a community of 439,942 IT Pros & Developers. It's quick & easy.

# Dictionary complements if, elif, else

 Expert Mod 2.5K+ P: 2,851 We are parametrically attaching a bent plate object to the side of a building column for support of a skewed beam. Given a relative rotation between the column and beam and which side of the column to attach to, the following code determines the X and Y direction flags to calculate the exact location and the rotation tuple of the bent plate object. Here's the old code (about 5 years old): Expand|Select|Wrap|Line Numbers if _relrotation > 0.0 and _relrotation < 90.0:     _caseno = "Case 1"     _xflg = 1     _yflg = 1 elif _relrotation > 90.0 and _relrotation < 180.0:     _caseno = "Case 2"     if _hssflgweb == "Short Side":         _xflg = -1         _yflg = -1     else:         _xflg = -1         _yflg = 1 elif _relrotation > 180.0 and _relrotation < 270.0:     _caseno = "Case 3"     if _hssflgweb == "Short Side":         _xflg = -1         _yflg = 1     else:         _xflg = 1         _yflg = -1   elif _relrotation > 270.0 and _relrotation < 360.0:     _caseno = "Case 4"     if _hssflgweb == "Short Side":         _xflg = 1         _yflg = -1     else:         _xflg = -1         _yflg = -1   if case_no == "Case 1" or case_no == "Case 3":     rot_argument = [rel_rotation, 0.0, 0.0] elif case_no == "Case 2" or case_no == "Case 4":     rot_argument = [180.0 - rel_rotation, 0.0, 180.0] if hss_flg_web == "Long Side":     rot_argument[0] = 180.0 - rot_argument[0]     rot_argument[2] = rot_argument[2] + 180.0   I just updated the code: Expand|Select|Wrap|Line Numbers caseDict = {"Case 1": {"Long Side": (1,1,(180.0-relRot, 0.0, 180.0)), \                        "Short Side": (1,1,(relRot, 0.0, 0.0))}, \             "Case 2": {"Long Side": (-1,1,(relRot, 0.0, 0.0)), \                        "Short Side": (-1,-1,(180.0-relRot, 0.0, 180.0))}, \             "Case 3": {"Long Side": (1,-1,(180.0-relRot, 0.0, 180.0)), \                        "Short Side": (-1,1,(relRot, 0.0, 0.0))}, \             "Case 4": {"Long Side": (-1,-1,(relRot, 0.0, 0.0)), \                        "Short Side": (1,-1,(180.0-relRot, 0.0, 180.0))}             }   if 0.0 < relRot <= 90.0:     caseno = "Case 1" elif 90.0 < relRot <= 180.0:     caseno = "Case 2" elif 180.0 < relRot <= 270.0:     caseno = "Case 3" else:     caseno = "Case 4"   self.xflg, self.yflg, self.rot = caseDict[caseno][flgweb] I still have an if, elif, else, but it's cleaner and easier to read. Nov 18 '07 #1