How Do Data Structures help us to be better programmers
Why do we learn Data Structure?
How does Data Structure help?
Is it necessary to keep it in our minds?
Why are we programming?
To Digitize the real-time process.
In order to do data operations should have knowledge of Data Structures. Like List, Dictionaries, Sets, Map, SQL Tables, Documents, and DataFrames, etc...
What is Data Structure?
The basic Python data structures in Python include list, set, tuples, and dictionary. Each of the data structures is unique in its own way. Data structures are “containers” that organize and group data according to type.
How does data structure help?
To manipulate, compute the data and achieve the result we want.
Is it necessary to keep it in our minds?
If you know the Data Structures, there is No need to be afraid of the different programming languages.
You can easily jump into any kind of programming Because you are good at Data Structures. You are going to find the syntax for respective programming for data handling.
I’m not saying you can be superman in a new programming language at first, But you can’t be a novice in handling data.
How do Data Structures help us to be better programmers?
In Programming, we can’t rely on a single programming language, According to the business case scenario have to choose the respective language which helps us to solve the problem.
At that time, Data Structures helps us to think in a General way. You won't feel like a newbie.
Yeah of course! You have to put an amount of effort to understand the basics of a new language, in that no compromise.
Example Use Case:
Data in JSON format:
employee_details = {
"DataEngineering":
[{
"EmpName" : "Chris Jackman", "EmpAge" : "34", "EmpGender" : "Male",
"EmpDesg" : "Project Manager", "EmpId":1
},
{
"EmpName" : "Mary Jane", "EmpAge" : "27", "EmpGender" : "Female",
"EmpDesg" : "Team Leader", "EmpId":2
},
{
"EmpName" : "Ramesh", "EmpAge" : "27", "EmpGender" : "Male",
"EmpDesg" : "Module Lead", "EmpId":3
}
],
"Testing":
[{
"EmpName" : "Varu", "EmpAge" : "34", "EmpGender" : "Female",
"EmpDesg" : "Project Manager", "EmpId":4
},
{
"EmpName" : "Paul", "EmpAge" : "35", "EmpGender" : "Male",
"EmpDesg" : "Team Leader", "EmpId":5
},
{
"EmpName" : "John", "EmpAge" : "27", "EmpGender" : "Male",
"EmpDesg" : "Module Lead", "EmpId":6
}
]
}
from the above JSON data, I wish to get the employee count in gender-wise.
Logic Steps To Achieve this:
- Declare 2 Variables to store MaleCount and FemaleCount
- ‘Iterate employee_details JSON and get a list of employees for that department.
- Iterate that employee list of a particular department
- Check the “EmpGender” of that employee
- If its Male, then add value 1 into MaleCount Variable
- If its Female, then add value 1 into FemaleCount Variable
here is the syntax in python
male_employee_count = 0
female_employee_count = 0
for ed in employee_details:
department_employee_list = employee_details[ed]
for de in department_employee_list:
if de['EmpGender']=='Male':
male_employee_count+=1
elif de['EmpGender']=='Female':
female_employee_count+=1
print("male_employee_count=",male_employee_count)
print("female_employee_count=",female_employee_count)
#output
male_employee_count = 4
female_employee_count = 2
This logic is can apply to this kind of data in any programming language. Only syntax gets changed.
Data in Table format:
Assume you have this data in the SQL table. Then SQL query will be
SELECT
COUNT(EmpId) ,EmpGender
FROM
EmployeeTable a
GROUP BY
EmpGender;
-------------------------------------------------
OUTPUT:
---------------
| Male | 4 |
---------------
|Female | 2 |
---------------
If the data is in a table format, then applying logic to retrieving the data might differ.
In SQL we don't need to “Iterate” it by each Department. “GroupBy” will do that job.
Data in LIST format:
gender_list = ["Male","Female","Male","Female","Male","Male"]
#code
male_employee_count = 0
female_employee_count = 0
for gender in gender_list:
if gender=="Male":
male_employee_count+=1
else:
female_employee_count+=1
print("male_employee_count=",male_employee_count)
print("female_employee_count=",female_employee_count)
#output
male_employee_count = 4
female_employee_count = 2
In the above LIST data, we have only a list of gender.
Iterating each LIST and checking the element type and adding value 1 into a respective variable.
Based on the data type we have to apply logic.
Explore well-efficient features available in the respective data types and use them effectively.
Key Benefits of Knowing Data Structures:
- Low code
- Logical thinking
- Dynamic programming
- Performance
- Quick understanding of any kind of data
- Data integrity
- Debug
- Self-confidence on programming
************************Happy Coding :smile: *****************************