General FizzBuzz: Difference between revisions
Content added Content deleted
ReeceGoding (talk | contribs) m (→{{header|R}}: Syntax highlighting.) |
(→Python - Unelegant naive version: remove inelegant, unpythonic version) |
||
Line 2,892: | Line 2,892: | ||
19 |
19 |
||
Buzz</pre> |
Buzz</pre> |
||
===Unelegant naive version=== |
|||
'''First contribution to rosettacode, uses list comprehension to join the lists and args to allow for arbitrary range''' |
|||
<lang python>def genfizzbuzz(numberlist, wordlist, *args): |
|||
nml = [[numberlist[i], wordlist[i]] for i in range(len(numberlist))] |
|||
for z in range(*args): |
|||
res = "" |
|||
for j in nml: |
|||
if z % j[0] == 0: |
|||
res += j[1] |
|||
print(res or z) |
|||
genfizzbuzz([3, 5, 7], ['Fizz', 'Buzz', 'Baxx'], 1, 21) |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
1 |
|||
2 |
|||
Fizz |
|||
4 |
|||
Buzz |
|||
Fizz |
|||
Baxx |
|||
8 |
|||
Fizz |
|||
Buzz |
|||
11 |
|||
Fizz |
|||
13 |
|||
Baxx |
|||
FizzBuzz |
|||
16 |
|||
17 |
|||
Fizz |
|||
19 |
|||
Buzz |
|||
</pre> |
|||
===One liner using generator expressions=== |
===One liner using generator expressions=== |