Computer Science

How to Create a List of Dictionaries in Python?

Problem: Say, you have a dictionary {0: ‘Alice’, 1: ‘Bob’} and you want to create a list of dictionaries with copies of the original dictionary: [{0: ‘Alice’, 1: ‘Bob’}, {0: ‘Alice’, 1: ‘Bob’}, {0: ‘Alice’, 1: ‘Bob’}]. You use list comprehension with a “throw-away” loop variable underscore _ to create a list of 3 elements. …

How to Create a List of Dictionaries in Python? Read More »

SQLite Python Placeholder – Four Methods for SQL Statements

Are you confusing about SQLite Python Placeholders? It’s time for better understanding! Learn how in this tutorial. Introduction SQLite is an embedded open-source relational database engine. Its developers, from SQLite.org, call it a self-contained, serverless, zero-configuration, fast, reliable and transactional SQL database engine.  It keeps things simple. SQLite “just works.” The SQLite library is also …

SQLite Python Placeholder – Four Methods for SQL Statements Read More »

What Does “if __name__ == ‘__main__'” Do in Python?

Today, let’s discuss something that’s all over the place in many code bases: what does if __name__ == ‘__main__’ do in Python? The statement if __name__ == ‘__main__’: checks if variable __name__ is set to the string value ‘__main__’ which holds only within the main source file from which you initially execute your code. In all other …

What Does “if __name__ == ‘__main__’” Do in Python? Read More »