<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Writing idiomatic python code
the Zen of Python
Step1:  PEP8
Let's have a look
Step5:  Thuthiness is defined by __bool__() method
Step6:  What's the pythonic way?
Step7:  Don't be this guy
Step8:  Testing for None
python
if something is None
Step9:  Sometimes can be a bit slower if used inside a long loop.
Checking for type
Step10:  How to check if the variable is a list or dictionary?
Step11:  Checking if an object is iterable?
Step12:  Similar way, by checking the methods
Step13:  Another way
Step14:  won't work, because Python does not automatically convert to str
Step15:  Pythonic
Step16:  using dictionaries
Step17:  f-strings (Python 3.6+)
Just pulling variables from the namespace!
Step18:  References
Write Pythonic Code Like a Seasoned Developer
<ASSISTANT_TASK:>
Python Code:
import this
Explanation: Writing idiomatic python code
the Zen of Python
End of explanation
if []:
    print('this is false')
False     # false is false
[]        # empty lists
{}        # empty dictionaries or sets
""        # empty strings
0         # zero integers
0.00000   # zero floats
None      # None (but not zero)
Explanation: PEP8
Let's have a look: https://www.python.org/dev/peps/pep-0008/
Static checkers in editors and GitHub
Naming conventions
Names should be descriptive!
Rule of thumb: If you need a comment to describe it, you probably need a better name.
```python
import my_module_name
from foo import bar
constant, not changed at runtime
MODEL_GRID = 'cartesian'
def calculate_something(data):
    Compute some parameters
    # ...
    return result
class ModelDomain(object):
    
    Very long description...
    Attributes: ...
    Parameters: ...
    
    def init(self, name='', description='', bounds=None, mask_bounds=None):
        self.name = name
        self.description = description
        # something else...
def mask_var(self, data):
    Mask the data of the given variable outside the region.
    return data.where(self.mask_bounds, data)
class MyDescriptiveError(Exception):
    pass
```
A handful of foundational concepts
Truthiness
End of explanation
class MyClass:
    def __init__(self, data):
        self.data = data
    def __bool__(self):
        if len(self.data) > 0:
            return True
        else:
            return False
foo = MyClass(data=[1, 2, 3])
if foo:
    print('it contains some data')
else:
    print('no data')
Explanation: Thuthiness is defined by __bool__() method
End of explanation
vrbl = True
if vrbl:
    # NO: if condtion == True
    print('do something')
Explanation: What's the pythonic way?
End of explanation
def test_if_greater_than_ten(x):
    return True if x>10 else False
test_if_greater_than_ten(11)
def fun():
    print('blah')
x = fun
x()
type(x)
callable(x)
isinstance(12345, (int, float))
Explanation: Don't be this guy:
<img src="https://imgur.com/24DSLiA.png">
End of explanation
my_axis = 'x'
if my_axis in ('x', 'y'):
    # Instead of writing like that:
    # if my_axis == 'x' or my_axis == 'y'
    print('horizontal')
elif my_axis == 'z':
    print('vertical')
Explanation: Testing for None
python
if something is None:
    print('no results')
else:
    print('here are some results')
negation:
python
if something is not None:
    print('Option A')
else:
    print('Option B')
Multiple tests against a single variable
End of explanation
a = [1,2,3]
Explanation: Sometimes can be a bit slower if used inside a long loop.
Checking for type
End of explanation
import numpy as np
a = np.arange(10)
isinstance(a, np.ndarray)
Explanation: How to check if the variable is a list or dictionary?
End of explanation
the_variable = [1, 2, 3, 4]
another_variable = "This is my string. There are many like it, but this one is mine."
and_another_variable = 1000000000000
for i in another_variable[:10]:
    # iterate over the first 10 elements and print them
    print(i)
import collections
if isinstance(1234563645, collections.Iterable):
    # iterable
    print('It is iterable')
else:
    # not iterable
    print('It is NOT iterable')
Explanation: Checking if an object is iterable?
End of explanation
hasattr(the_variable, '__iter__')
Explanation: Similar way, by checking the methods:
End of explanation
day = 30
month = 'October'
Explanation: Another way: duck-typing style
Pythonic programming style that determines an object's type by inspection of its method or attribute signature rather than by explicit relationship to some type object ("If it looks like a duck and quacks like a duck, it must be a duck.") By emphasizing interfaces rather than specific types, well-designed code improves its flexibility by allowing polymorphic substitution. Duck-typing avoids tests using type() or isinstance(). Instead, it typically employs the EAFP (Easier to Ask Forgiveness than Permission) style of programming.
python
try:
   for i in the_variable:
        # ...
except TypeError:
   print(the_variable, 'is not iterable')
Source: https://stackoverflow.com/a/1952481/5365232
Modern string formatting
End of explanation
print('Today is ' + month + ', ' + str(day))
Explanation: won't work, because Python does not automatically convert to str:
python
print('Today is ' + month + ', ' + day)
Works, but not pythonic:
End of explanation
print('Today is {}, {}'.format(month, day))
print('Today is {1}, {0}'.format(month, day))
print('Today is {1}, {0}. Tomorrow will be still {0}'.format(month, day))
print('Today is {m}, {d}. Tomorrow will be still {m}. And again: {d}'.format(m=month, d=day))
Explanation: Pythonic:
End of explanation
data = {'dow': 'Monday', 'location': 'UEA', 'who': 'Python Group'}
print('Today is {dow}. We are at {location}.'.format(**data))
Explanation: using dictionaries
End of explanation
print(f'Today is {day}th. The month is {month}')
# print(f'Today is {data["dow"]}. We are at {data["location"]}')
Explanation: f-strings (Python 3.6+)
Just pulling variables from the namespace!
End of explanation
HTML(html)
Explanation: References
Write Pythonic Code Like a Seasoned Developer
End of explanation
<END_TASK>