How to golf in python

Had some fun in c.l.py.
Given was:

def fizzbuzz(num):
> if num:
> if num % 15 is 0: return fizzbuzz(num-1) + 'fizzbuzz \n'
> elif num % 5 is 0: return fizzbuzz(num-1) + 'buzz \n'
> elif num % 3 is 0: return fizzbuzz(num-1) + 'fizz \n'
> else : return fizzbuzz(num-1) + ('%d \n' % num)
> return ''
> print fizzbuzz(100)

Since this was not funny enough, I wrote:
for i in range(1,101):print('','fizz')[not i%3]+('','buzz')[not i%5]or i

This works because not casts to bool and (True, False) == (1, 0).
It also exploits short circuit evaluation and the fact that the or matches against the result of + due to evaluation order, where '' would yield False.

I guess I should give perl another try someday to get this in a half line :)

Trackback URL for this post:

http://www.pronweb.de/trackback/491

I am very thankful to you

I am very thankful to you for posting such stuff.This really help me lot.I really appreciate your work.Wow, that looks so good!

-----------------------------------------------
We delight in bringing you beautiful fine jewelry discoveries and values. Our Necklaces have been beautifully designed and carefully created to match the aesthetics as well as the practicality. Our range of fashion necklace includes girls necklaces, resin necklace, polymer clay jewelry, pendant necklaces, pearl necklaces.

DhynYj

MXxffct DhynYj

viagra dosage

cialis

kMODomh cialis kSwzQ comprare viagra rPDjK cipro 2220 kamagra on line EtccN levitra 1754 clomid IdOli

cipro bestellen

cipro

KlcIZAo cipro 9955 Cheap viagra Hzfiem Levitra cQNNqj zithromax GXjvuj Buy priligy >:-OOO generic Cialis 0889

viagra kopen

TmnJaHnK viagra kopen 9333 nolvadex 7445 diflucan on line GSXwE Koop cipro 8990 cipro 5652 viagra iCDukw

levitra Genérico

lasix prix

gNqjPMR lasix prix 8]]] viagra 3804 amoxil 2207 zithromax 8]]] viagra Generique 0884 viagra dAwfvJ

Lasix

bsVfrd Lasix VoOWkE Combivir locflh Levitra cTfeb Buy Cialis 7537 viagra soft 0172 buy Clomid hVmsxR

cialis

propecia Generico

synthroid

VaNiQHDj synthroid 3641 cialis bjTEf levitra 1036 cialis on line ELTpTu clomid zknkc comprare cialis 9217

viagra

JocNQtZ viagra QbJWVi viagra 100 mg >:]] viagra 8]]] buy Clomid 3773 viagra =-]

auto insurance

order zithromax

ISkbSFBv order zithromax URrpQ Cheap Cialis 2805 Priligy %-[[[ viagra 8]]] cialis 0766 viagra online MGyPUA

payday loans

propecia

BEfkNUM propecia TfAptM levitra VHPqaT cialis %-[[[ amoxil rezeptfrei ZHSKc viagra 8]]] cialis 8]]]

cipro prix

fJXtCJvQ cipro prix OrNHO cipro VKYKI diflucan on line :-O viagra URvRTK propecia 9073 werking cialis fYIHCn

instant online payday loans

instant payday loans uk only

viagra generico

NJByMQ viagra generico fgPPfu nolvadex kaufen xufTE venta viagra >:-OOO

cialis

ZUGBvB cialis 9079 cialis pil dXfLlV acheter clomid 1239

Cheap zithromax

OQPJxdVh Cheap zithromax >:-[ cialis bestellen >:]] lasix >:]]

auto loans

car loans

zACaDJr car loans 7692 instant payday loans qXnZnr

buy viagra online

KyBzZI buy viagra online TQPFBd cialis 0240

viagra

iDkIGsC viagra HGSrgu cialis =-]

payday loans

viagra

ehnudo viagra 9769 viagra coupon WPdeMp diflucan 3482

california payday loans

viagra

IhddYNiX viagra =-] levitra mDRty levitra generico gWXGwM

buy Clomid

priligy bestellen

vVxlCys priligy bestellen >:]] cialis 6143 priligy 2996

payday loans

viagra pil

xcdcVv viagra pil 1717 priligy >:]] viagra vente mbGwjZ

cialis

tECzGD cialis %-[[[ cialis %-[[[ Levitra 2246

cash online

PLcQAK cash online kepcz payday loans UK KJDpjL

generic Cialis

fawfFdmb generic Cialis knYlZy viagra coupon TOSLA cialis MVFsUb

levitra

nsLilxP levitra >:]] levitra >:-[ cialis LuUSD levitra :-O

same day payday loans

nULzpafU same day payday loans 6290 payday loan XKuCPz

Cialis

HUZXhDs Cialis >:]] viagra oAWtY cialis 7329

lariam

MMeRFW lariam 8]]] generic Cialis >:-OOO

cash online

bOiCHa cash online QWGgVf payday loan online 5669

cash online

Cialis

gXtGXni Cialis 5667 cialis vPseLO viagra 2769

viagra precio

LMBPqsjJ viagra precio %-[[[ cialis KIKdkA venda viagra >:]]

cash advance

rPKBstv cash advance nGruAn cash advance 5962

cialis ohne rezept

BzsSMLkj cialis ohne rezept weUdS viagra wtPgN viagra prijs unrZQ

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • E-Mail addresses are hidden with reCAPTCHA Mailhide.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions. Once you passed the test, you wont be challenged anymore.
Type in the two words: