Common Tips


Note that from myModule import * shouldn’t be used. If done, all the global variables defined in myModule will appear in the current namespace. Modulus should not pollute each other.

Lists and npArrays

1- Lists are (much) faster than npArrays when accessing or appending elements. However, npArrays are faster when doing linear algebra operations. It is more efficient to manipulate data in the form of lists and then convert them into npArrays when dealing with large data.


1- A set of sets: frozenset()

listOfSets1 = [{5},{1,2},{3,4},{5,7,9}]
listOfSets2 = [{11},{1,2},{12,16},{5,7,9},{7,23,13}]
setOfSets1 = {frozenset(eachSet) for eachSet in listOfSets1}
setOfSets2 = {frozenset(eachSet) for eachSet in listOfSets2}
Out[39]: {frozenset({5, 7, 9}), frozenset({1, 2})}


1- Type hinting

def myFunction(text: str, flag: bool, name: str = "Aristotle") -> str: