In wikipedia struct is :
A struct in the C programming language (and many derivatives) is a composite data type (or record) declaration that defines a physically grouped list of variables under one name in a block of memory, allowing the different variables to be accessed via a single pointer or by the struct declared name which returns the same address. The struct data type can contain other data types so is used for mixed-data-type records such as a hard-drive directory entry (file length, name, extension, physical address, etc.), or other mixed-type records (name, address, telephone, balance, etc.).
Tricks how to simplify if else or switch case in your code …
A high-level programming language statement that compares two or more sets of data and tests the results. If the results are true, the THEN instructions are taken; if not, the ELSE instructions are taken.
The following is a BASIC example:
10 if answer = "y" then print "Yes"
20 else print "No"
In many languages, THEN is implied. All statements between IF and ELSE are carried out if the condition is true. …
One of the most common design patterns that every developer needs to know is the Singleton Design pattern. Wikipedia defines the Singleton Pattern as:
The singleton pattern is a software design pattern that restricts the instantiation of a class to one object.
To translate that in Go, whenever any goroutine tries to access an instance of a variable, you should get the same variable.
There are various ways to implement the singleton pattern in Go, but it is also quite easy to get it wrong. …
When you are asked to create a simple API that returns data in an address table, in this table there is a column for a country name, city name, district name and address as shown below
This is the reason why you should not use for loops in your python code
Python provides compact syntax for deriving one list from another. These expressions are called list comprehensions. List comprehensions are one of the most powerful tools in Python. Python’s list comprehension is an example of the language’s support for functional programming concepts.
The Python list comprehensions are a very easy way to apply a function or filter to a list of items. List comprehensions can be very useful if used correctly but very unreadable if you’re not careful.
How easy load data sets from python …
The NamedTuple is another class, under the collections module. Like the dictionary type objects, it contains keys and that are mapped to some values. In this case we can access the elements using keys and indexes.
To use it at first we need to import it the collections standard library module.
In this section we will see some functions of the NamedTuple class.
From NamedTuple, we can access the values using indexes, keys and the getattr() method. The attribute values of NamedTuple are ordered. …
Explaination when to using _ and __ underscore in python
Single and double underscores have a meaning in Python variable and method names. Some of that meaning is merely by convention and intended as a hint to the programmer and some of it is enforced by the Python interpreter.
If you’re wondering “What’s the meaning of single and double underscores in Python variable and method names?” Here’s an explaination.
In this article I’ll discuss the following five underscore patterns and naming conventions and how they affect the behavior of your Python programs:
Memoization is a way of caching the results of a function call. If a function is memoized, evaluating it is simply a matter of looking up the result you got the first time the function was called with those parameters. This is recorded in the memoization cache. If the lookup fails, that’s because the function has never been called with those parameters. Only then do you need to run the function itself?
Memoization only makes sense if the function is deterministic, or you can live with the result being out of date. But if the function is expensive, memoization can…