› Kinyanjui Wangonya

Software engineer - previously at Andela, now at Jenga.

What happens when a variable is assigned to another variable in python? For example:

>>> x = 5
>>> y = x

Both x and y will have the value 5. But, when x was assigned to y, y was not created as a completely new/separate object. Instead, an alias for x was created. That is, y points to the memory location of x. It does not have it’s own memory location - yet.

>>> id(x)
>>> id(y)
>>> x is y

By default, variables are immutable in Rust. Coming from a Python background, I have to keep in mind that this:

fn main() {
    let var = 10;
    println!("var = {}", var);  // var = 10
    var = 5;  // try and reassign var
    println!("var is now {}", var);

… will not compile.

The range() function is often useful when iterating over a set of integers:

for n in range(50):


for n in range(10, 30):

or a list of strings:

for fruit in ["apple", "mango", "banana"]:

Say we have a list of strings: _list = [...,] and user input _input = '...', how do we find the items in _list that most closely resemble _input?

Python has a built-in package called difflib with the function get_close_matches() that can help us.

Note: * represents a required parameter.




iterable*: a python iterable e.g a list, tuple, string, dictionary or set.

Return value

Returns a string concatenated with the elements of the passed in iterable.




capitalize() takes no parameters.

Return value

Returns a copy of the string with the first letter of the first word capitalized and all the other characters of the string in lowercase.

I just came across this online HTML to JSX Compiler. If you’re new (or not) to react and you’re still having a little trouble with JSX, I think this tool is great for learning.

Note: * represents a required parameter.



string.find(substring, start, end)

substring*: the substring to be searched in the string.

start: index from which to begin the search.

end: index at which to end the search.

Return value

Returns an integer value pointing to the index of first occurrence of the substring. If the substring is not found, it returns -1.

A lot of times when I’m doing ifs in Python, I find myself wondering whether to use is or == for the check.

# do I do
if a is b:

# or
if a == b:

It can be a bit confusing if you’re new to Python, and it’s easy to assume the two can be used interchangeably. So, what’s the difference?

I’ve been reading the book “Smarter Faster Better” by Charles Duhigg and in it, he gives a perspective on goal-setting that I found interesting.

You may already know about SMART goals, which is an awesome format to set your goals in. It does have a subtle pitfall though: cognitive closure.

« Older posts Newer posts »