Skip to content

Instantly share code, notes, and snippets.

View amelieykw's full-sized avatar

amelieykw amelieykw

  • Sophia Antipolis, France
View GitHub Profile
@amelieykw
amelieykw / 1 - What is counter?.md
Last active July 15, 2018 16:47
[Python - Counters in Python | Set 1 (Initialization and Updation)] #Python #tutorial #interview #Counter #Initialization #Updation

Counter is a container included in the collections module.

@amelieykw
amelieykw / 1 - C-style approach.md
Last active July 15, 2018 16:38
[Python - Using Iterations in Python Effectively] #Python #Iterations

This approach requires prior knowledge of total number of iterations.

# A C-style way of accessing list elements
cars = ["Aston", "Audi", "McLaren"]
i = 0
while (i < len(cars)):
    print cars[i]
    i += 1
@amelieykw
amelieykw / end parameter in print().md
Created July 14, 2018 21:31
[Python - end parameter in print()] #Python #end #print() #interview #tutorial

By default python’s print() function ends with a newline.

Python’s print() function comes with a parameter called ‘end’.

By default, the value of this parameter is ‘\n’, i.e. the new line character. You can end a print statement with any character/string using this parameter.

# This Python program must be run with
# Python 3 as it won't work with 2.7.
 
@amelieykw
amelieykw / 0 - Background.md
Last active July 14, 2018 21:24
[Python - Packing and Unpacking Arguments] #Python #tutorial #interview #packing #unpacking #argument

We use two operators * (for tuples) and ** (for dictionaries).

Background

# A Python program to demonstrate need 
# of packing and unpacking
 
# A sample function that takes 4 arguments
# and prints them.
def fun(a, b, c, d):
@amelieykw
amelieykw / Transpose a matrix in Single line in Python.md
Created July 14, 2018 19:11
[Python - Transpose a matrix in Single line in Python] #Python #tutorial #interview

Transpose of a matrix is a task we all can perform very easily in python (Using a nested loop). But there are some interesting ways to do the same in a single line.

Matrix

In Python, we can implement a matrix as nested list (list inside a list).

Each element is treated as a row of the matrix.

For example m = [[1, 2], [4, 5], [3, 6]] represents a matrix of 3 rows and 2 columns. First element of the list – m[0] and element in first row, first column – m[0][0].

@amelieykw
amelieykw / Django Lineage.md
Created July 13, 2018 16:55
[Django Horizontal Tab Lineage]
@amelieykw
amelieykw / 00 - Table of Contents.md
Created July 13, 2018 10:09
[Creating forms from models.md] #forms #models #Django #Creating_forms_from_models

Contents Creating forms from models ModelForm Field types A full example Validation on a ModelForm Overriding the clean() method Interaction with model validation Considerations regarding model’s error_messages The save() method

@amelieykw
amelieykw / 00 - Table of Contents.md
Created July 13, 2018 07:49
[Django - Formset] #Formset #Django
  • Formsets
    • Using initial data with a formset
    • Limiting the maximum number of forms
    • Formset validation
    • Validating the number of forms in a formset
    • Dealing with ordering and deletion of forms
    • Adding additional fields to a formset
    • Passing custom parameters to formset forms
    • Customizing a formset’s prefix
    • Using a formset in views and templates