Create a list with predefined number of entries in python

You want to create an array-like data structure in python. You know, how many entries you will need for your list. What do you do?

I always thought you have to do something like

lst = []
for i in range(N):

Today i learned here, that in python you can simply say

lst = [None]*N

and it is even much faster. I never stop learning, even after several years of using python 🙂

Dieser Eintrag wurde in Python veröffentlicht.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.