<jupyter_start><jupyter_text>What is Pythonic? I like the following explanation: "Pythonic means code that doesn't just get the syntax right but that follows the conventions of the Python community and uses the language in the way it is intended to be used."-- dreftymac http://stackoverflow.com/a/25011492/2213697<jupyter_code>import this
import this
# Bad example
lst1 = ["Hello", "we", "are", "doing", "python"]

i = 0

while i < len(lst1):
    print ("The %dth element is %s" % (i, lst1[i]))
    i = i + 1
    
lst1 = ["Hello", "we", "are", "doing", "python"]

for e in lst1: # oh but the index?
    print (e)
lst1 = "Hello we are doing python".split(" ")

for i, e in enumerate(lst1):
    print ("The %dth element is %s" % (i, e))
lst1 = "Hello we are doing python".split(" ")

for e in reversed(lst1): # faster then everthing else with indx
    print (e)
lst1 = "Hello we are doing python".split(" ")
lst2 = "And we are it smart".split(" ")

for i, (e1,e2) in enumerate(zip(lst1, lst2)): # izip in python2
    print (e1, e2)
lst1 = "Hello we are doing python".split(" ")

for e in sorted(lst1): # faster then everthing else with indx
    print (e)<jupyter_output>Hello
are
doing
python
we<jupyter_text>Implementing find<jupyter_code>def find():
    lst1 = ["Hello", "we", "are", "doing", "python"]
    found = False
    for i, value in enumerate(lst1):
        if value == "we":
            found = True
            break
    if not found:
        return "Not Found"
    else:
        return i
    
print (find())

# Else on loops:
# If a break its fine, if not go to else
def find():
    lst1 = ["Hello", "we", "are", "doing", "python"]
    found = False
    for i, value in enumerate(lst1):
        if value == "2we":
            break
    else:
        return "Not Found"
    return i
print (find()) # What just happend?<jupyter_output>Not Found<jupyter_text>For over dict's<jupyter_code>dic = {"a" : "We", "b" : "are", "c" : "using", "d" : "python"}
for k in dic:
    print (k)
dic = {"a" : "We", "b" : "are", "c" : "using", "d" : "python"}
for k, v in dic.items(): # in python 2 use iteritems not items()
    print (k, v)<jupyter_output>a We
b are
c using
d python<jupyter_text>Again on difference between python2 and python3, 3 gos with indecies 2 with values and then over time implemted i<jupyter_code># Count with a dic
colors = ["red", "blue", "blue", "green", "red", "red"]
d = {}
for color in colors:
    if color not in d:
        d[color] = 0
    d[color] += 1
d
d = {}
for color in colors:
    d[color] = d.get(color, 0) + 1
d
import collections
d = collections.defaultdict(int)
for color in colors:
    d[color] += 1
d
def fibonacci (n):
    x = 0
    y = 1
    for i in range(n):
        print (x)
        t = y
        y = x + y
        x = t
        
fibonacci(5)
def fibonacci (n):
    x, y = 0, 1
    for i in range(n):
        print (x)
        x, y = y,  x + y
        
fibonacci(5)<jupyter_output>0
1
1
2
3<jupyter_text>Unpacking<jupyter_code>a, b = 0, 1
a, b = b, a
a, b
a, (b, c) = 1, (2, 3)
c
# Only avalible in python 3
a, *rest = [1, 2, 3]
print ("a =  %s" % a)
print ("rest =  %s" % rest)

a, *middle, c = [1, 2, 3, 4]
# a = 1, middle = [2, 3], c = 4

print ("a =  %s" % a)
print ("middle =  %s" % middle)
print ("c =  %s" % c)<jupyter_output>a =  1
middle =  [2, 3]
c =  4
{'fraction_non_alphanumeric': 0.15291628890903597, 'fraction_numerical': 0.025385312783318223, 'mean_word_length': 2.839907192575406, 'pattern_counts': {'":': 2, '<': 17, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '404445', 'license': 'MIT', 'n_tokens_mistral': 1318, 'n_tokens_neox': 1260, 'n_words': 467, 'path': '02_Pythonic.ipynb', 'repo_name': 'SamyStyle/python-tutorial', 'size': '3309'}