title: Python - efficiently select from list based on user input
body: <p>I'm wondering if anyone can help me figure out a more efficient way to select an index out of a list based on user input this is the best way I've come up to do it, the only other way I could think is to manually set the value with a loop. Just to note those print statements are in a function so I can collapse them to make the code more readable in the IDE. Here's what I have, any feedback would be appreciated:</p>
  
  <pre><code>def LBMethodList():
       print "Load balance Methods"
       print "____________________"
       print "1  - Round Robin"
       print "2  - Ratio (member)"
       print "3  - Least Connections (member)"
       print "4  - Observed (member)"
       print "5  - Predictive (member)"
       print "6  - Ratio (node)"
       print "7  - Least Connections (node)"
       print "8  - Fastest (node)"
       print "9  - Observed (node)"
       print "10 - Predictive (node)"
       print "11 - Dynamic Ratio (node)"
       print "12 - Fastest (application)"
       print "13 - Least Sessions"
       print "14 - Dynamic Ratio (member)"
       print "15 - Weighted Least Connections (member)"
       print "16 - Weighted Least Connections (node)"
       print "17 - Ratio (session)"
       print "18 - Ratio Least Connections (member)"
       print "19 - Ratio Least Connections (node)"
  
  class LBMethodConvert:
  LBMethodList()
  ListLBMethod = ["LB_METHOD_ROUND_ROBIN", "LB_METHOD_RATIO_MEMBER", "LB_METHOD_LEAST_CONNECTION_MEMBER",
                  "LB_METHOD_OBSERVED_MEMBER", "LB_METHOD_PREDICTIVE_MEMBER", "LB_METHOD_RATIO_NODE_ADDRESS",
                  "LB_METHOD_LEAST_CONNECTION_NODE_ADDRESS", "LB_METHOD_FASTEST_NODE_ADDRESS",
                  "LB_METHOD_OBSERVED_NODE_ADDRESS", "LB_METHOD_PREDICTIVE_NODE_ADDRESS", "LB_METHOD_DYNAMIC_RATIO",
                  "LB_METHOD_FASTEST_APP_RESPONSE", "LB_METHOD_LEAST_SESSIONS", "LB_METHOD_DYNAMIC_RATIO_MEMBER",
                  "LB_METHOD_L3_ADDR", "LB_METHOD_WEIGHTED_LEAST_CONNECTION_MEMBER",
                  "LB_METHOD_WEIGHTED_LEAST_CONNECTION_NODE_ADDRESS", "LB_METHOD_RATIO_SESSION",
                  "LB_METHOD_RATIO_LEAST_CONNECTION_MEMBER", "LB_METHOD_RATIO_LEAST_CONNECTION_NODE_ADDRESS"]
  LBMethodSelect = input('Please select Load Balance method by number from list above: ')
  MethodConstraint  = LBMethodSelect - 1
  LBMethod = ListLBMethod[MethodConstraint:LBMethodSelect]
  </code></pre>