On Thu, Apr 18, 2013 at 2:52 PM, Alan Gauld <alan.ga...@btinternet.com>wrote:
> On 18/04/13 18:14, Danilo Chilene wrote: > > for command in commands: >> if arg in commands: >> print commands[command] >> else: >> print 'Invalid command' >> > > I don't understand what you are doing here? Its almost a random selection > mechanism? You print the command for every item in commands if arg is in > commands and Invalid Command for every command if its not? > Whatever its trying to do its massively inefficient. > > I thought you'd have wanted something like > > for command in commands: > if arg == command: > > print commands[command] > else: > print 'Invalid command' > > Which is roughly equivalent to: > > print commands.get(arg, 'Invalid command') > > but much less efficient! Hi Alan, Yes, I was doing it the wrong way. > > > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > > ______________________________**_________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor> >
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor