<jupyter_start><jupyter_text>Topic 1 - How to Stand Out in a Python Coding Interview  Iterate With enumerate() Instead of range()<jupyter_code>#Fizzbuzz problem
numbers = [45, 22, 14, 65, 97, 72]
for i,num in enumerate(numbers):
    if num % 3 == 0 and num % 5 == 0:
        numbers[i] = "Fizzbuzz"
    elif num % 3 == 0:
        numbers[i] = "fizz"
    elif num % 5 == 0:
        numbers[i] = "buzz"
numbers<jupyter_output><empty_output><jupyter_text>Use List Comprehensions Instead of map() and filter()<jupyter_code>square = [a*a for a in range(1,10)]
square<jupyter_output><empty_output><jupyter_text>Debug With breakpoint() Instead of print()<jupyter_code>breakpoint()<jupyter_output>--Call--
> /home/skhk6342/anaconda3/lib/python3.7/site-packages/IPython/core/displayhook.py(252)__call__()
-> def __call__(self, result=None):
(Pdb) next
> /home/skhk6342/anaconda3/lib/python3.7/site-packages/IPython/core/displayhook.py(258)__call__()
-> self.check_for_underscore()
(Pdb) next
> /home/skhk6342/anaconda3/lib/python3.7/site-packages/IPython/core/displayhook.py(259)__call__()
-> if result is not None and not self.quiet():
(Pdb) exit<jupyter_text>Format strings With f-Strings<jupyter_code>a = "world"
print(f"hello {a}")<jupyter_output>hello world<jupyter_text>Sort Complex Lists With sorted()<jupyter_code>sorted([4,5,6,7,8], reverse=True)
animals = [
...     {'type': 'penguin', 'name': 'Stephanie', 'age': 8},
...     {'type': 'elephant', 'name': 'Devon', 'age': 3},
...     {'type': 'puma', 'name': 'Moe', 'age': 5},
... ]
animals
sorted(animals, key=lambda animal: animal['age'])<jupyter_output><empty_output><jupyter_text>Leverage Data Structures Effectively<jupyter_code>import random
all_words = "all the words in the world".split()
def get_random_word():
    return random.choice(all_words)
get_random_word()

# best apprach is to use set instead of list

def get_unique_word():
    words = set()
    for _ in range(1000):
        word = get_random_word()
        words.add(word)
    return words        
a = get_unique_word()
a
    # THis gives us o(n) operation which is faster than o(n2) if we would have used list<jupyter_output><empty_output><jupyter_text>Save Memory With Generators<jupyter_code>sum((i * i for i in range(1, 1001))) #faster than list comprehension<jupyter_output><empty_output><jupyter_text>Define Default Values in Dictionaries With .get() and .setdefault()<jupyter_code>cowboy = {'age': 32, 'horse': 'mustang', 'hat_size': 'large'}
#use get

cowboy.get('name', "man with no name")
name = cowboy.setdefault('name', 'The Man with No Name') # best way instaed of if and else checking
>>> student_grades = {}
>>> grades = [
...     ('elliot', 91),
...     ('neelam', 98),
...     ('bianca', 81),
...     ('elliot', 88),
... ]
# APproach one

for name, grade in grades:
    if name not in student_grades:
        student_grades[name] = []
    student_grades[name].append(grade)  
student_grades
#Approach 2 -- cleaner approach
from collections import defaultdict
students_grades = defaultdict(list)
for name, grade in grades:
    students_grades[name].append(grade)
students_grades<jupyter_output><empty_output><jupyter_text>Count Hashable Objects With collections.Counter<jupyter_code>from collections import Counter
words = "if there was there was but if \
there was not there was not".split()
counts = Counter(words)
counts
counts.most_common(2)<jupyter_output><empty_output><jupyter_text>Access Common String Groups With string Constants<jupyter_code>import string
string.ascii_uppercase
string.ascii_lowercase
# good when we have to check the upper character<jupyter_output><empty_output><jupyter_text>Generate Permutations and Combinations With itertools<jupyter_code>import itertools
friends = ['Monique', 'Ashish', 'Devon', 'Bernie']
list(itertools.permutations(friends, r=2))
list(itertools.combinations(friends, r=2))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1395169578622816, 'fraction_numerical': 0.022096608427543678, 'mean_word_length': 5.268921095008052, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '611344', 'license': 'MIT', 'n_tokens_mistral': 1446, 'n_tokens_neox': 1364, 'n_words': 332, 'path': 'Real_Python.ipynb', 'repo_name': 'shankarj67/Fullstack-Python', 'size': '3892'}