Help With Python

Steven Bethard steven.bethard at gmail.com
Wed Jan 26 16:25:02 EST 2005


Nick Vargish wrote:
> Here's my Monty Pythonic answer:
> 
> ## cut here
> class Viking():
> 
>     def __init__():
>         pass
> 
>     def order():
>         return 'Spam'
> 
> # this is one viking making one order repeated 511 times. if you want
> # 511 vikings making seperate orders, you'll have to write a loop.
> v = Viking()
> orders = [ v.order() ] * 511
> 
> print ', '.join(orders)

No need to write a loop:

py> class Viking(object):
...     def order(self):
...         return 'Spam'
...
py> v = Viking()
py> orders = [v.order()] * 7
py> ', '.join(orders)
'Spam, Spam, Spam, Spam, Spam, Spam, Spam'
py> orders = [Viking().order()] * 7
py> ', '.join(orders)
'Spam, Spam, Spam, Spam, Spam, Spam, Spam'

Steve



More information about the Python-list mailing list