[PYTHON] FizzBuzz in list comprehension

As an example, I will write a worn-out FizzBuzz in a Pythonic list comprehension. Real one liner.

def fizzbuzz(N):
    """FizzBuzz list comprehension implementation

    Example:
        >>> print fizzbuzz(10)
        [1, 2, 'Fizz', 4, 'Buzz', 'Fizz', 7, 8, 'Fizz', 'Buzz']

        >>> print fizzbuzz(30)
        [1, 2, 'Fizz', 4, 'Buzz', 'Fizz', 7, 8, 'Fizz', 'Buzz', 11, 'Fizz', 13, 14, 'FizzBuzz', 16, 17, 'Fizz', 19, 'Buzz', 'Fizz', 22, 23, 'Fizz', 'Buzz', 26, 'Fizz', 28, 29, 'FizzBuzz']

    """
    return [(i%3==0)*'Fizz' + (i%5==0)*'Buzz' or i for i in range(1, N+1)]

point

5. Embedded — Python 2.7.x documentation

Recommended Posts

FizzBuzz in list comprehension
List comprehension
List comprehension
FizzBuzz in Python
Python> Comprehension / Comprehension> List comprehension
Note: List comprehension
Sorted list in Python
Python Exercise 2 --List Comprehension
Python list comprehension speed
Filter List in Python
Not just list comprehension
List find in Python
If ... else in comprehension
Quicksort 2 | Easy list comprehension
list comprehension because operator.methodcaller cannot be used in python 2.5
Fizzbuzz in Python (in one line)
List of nodes in diagrams
Methods available in the list
Getting list elements in Python
[Road to intermediate Python] Use if statement in list comprehension
Extract multiple list duplicates in Python
[python] Manage functions in a list
Output 2017 Premium Friday list in Python
Judgment of if by list comprehension
Delete multiple elements in python list
When creating a matrix in a list
Linked list (list_head / queue) in C language
Python basic operation 1st: List comprehension notation
I want to print in a comprehension
Put together consecutive values in the list
[Linux] List of Linux commands used in practice
Display a list of alphabets in Python 3
Python comprehension (list and generator expressions) [additional]
OR the List in Python (zip function)
Change the list in a for statement
Difference between append and + = in Python list
Download images from URL list in Python
Summary of built-in methods in Python list
In search of the fastest FizzBuzz in Python
Get the EDINET code list in Python
[Python] Understand list slicing operations in seconds