Python Tips

Posted on Wednesday, Jul 01, 2020 in programming • Tagged with python, tips, lists, functools, itertools, timezone

A collection of small Python scripts and tips.

This post is based on a Twitter thread I started in April 2020 and works as a centralized way to read all the tips in an easier format than Twitter's 280 characters.

Both will be updated frequently.

List Flatten without explicit loops

  • Using Itertools' chain
1
2
3
4
5
6
import itertools

test = [[-1, -2], [30, 40], [25, 35]]
list(itertools.chain.from_iterable(test))

>>  [-1, -2, 30, 40, 25, 35]
1
2
3
4
test =  [[-1, -2], [30, 40], [25, 35]]
map(int, ''.join(c for c in test.__str__() if c not in '[]').split(',') )

>> [-1, -2, 30, 40, 25, 35]

Not pretty in my opinion ;)

Count individual items of any iterable

1
2
3
4
5
6
7
8
from collections import Counter
count = Counter(['a', 'b', 'c', 'a', 'a', 'b', 'd'])

print(count)
>> Counter({'a': 3, 'b': 2, 'c': 1, 'd': 1})

count['a']
>> 3

Repeat a series of values from any iterable

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
import itertools as it

data = it.cycle([1, 2])

for i in range(10):
    print(next(data))

>> 1
2
1
2
1
2
1
2
1
2

Name slices to reuse them

1
2
3
4
5
6
7
8
# slice(start, end, step)

STEPTWO = slice(None, None, 2)
integer_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

integer_list[STEPTWO]

>> [0, 2, 4, 6, 8]

This is the same as:

1
integer_list[::2]

Reverse any "indexable" collection that supports slices

1
2
3
4
5
6
# slice(None, None, -1) or [::-1]

integer_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
integer_list[::-1]

>> [9, 8, 7, 6, 5 …

Continue reading

Recruiting Tips for Recruiters

Posted on Wednesday, May 13, 2020 in eng-mgmt • Tagged with personal, software, engineering, recruiting, tips, hiring, management, sourcing

Since I started my professional life, several years ago, I've dealt with technical recruiters, that's great, right? I'm able to improve my quality of life, grow in a career path, and pursue interesting projects.

Unfortunately, my day to day experience with recruiters is not always great, usually, it takes a lot of time to filter interesting offers from less interesting ones. Based on my experience, I'll try and give a few hints on what makes the recruiting/sourcing process more enjoyable for engineers, engineering managers, product managers, and UX specialists, and hopefully with better results for recruiters.

Instead of ranting about a specific situation on Twitter, I thought it might be useful to describe what "good recruiting" looks like for me.

Let's start:

  1. Do your homework: most engineers and engineering managers I know maintain some kind of blog, Github profile, or LinkedIn profile. Some engineers give talks at local Meetups. They have invested a lot of time publicly sharing some of their work. It is nice to deal with recruiters that have taken their time reviewing that public information if recruiting is a numbers game, you'll drastically increase your chance of screening the right candidates if you do a little research beforehand. And... please, please, please, get the name right in your first contact you wouldn't believe me how many recruiters call me by another name...

  2. Be expressive with the job description: No, I'm not interested in a position I know nothing about, giving out my number to "know more", is not practical to anyone. Tell as much as you can about the position, the team, the kind of projects. The more information a possible candidate knows about the position the more interested (or not) they can be about continue the selection process. You want a software engineer to work …


Continue reading