March 2022

Distributed tracing is a method used to trace messages flowing through your business applications built using various Azure services, where they are well-suited for tracking and identifying any unexpected performance failures.

For instance, consider an employee onboarding application that involves multiple Azure services and on-premises components. Then, it might be challenging to trace and get complete visibility of data transferred between those services. That is where exactly distributed tracing can help you!

Serverless360 1

Hence, this blog aims to provide you with an ultimate solution that can meet all your logging and tracing needs, especially for cloud-native and hybrid applications involving Microsoft Azure.

Why Distributed Tracing for Azure and Hybrid Applications?

Distributed tracing is one best way to achieve ‘real-time’ visualization of how the message flows within your system, helping your Azure operations team better analyze your business process’s performance.

In all business sectors, including finance, healthcare, logistics, retail, telecommunications, and more, end-to-end tracing is widely used to address visibility challenges. Similarly, tracking is necessary for Azure and hybrid solutions to quickly understand the message flow, maximize visibility, pinpoint bottlenecks, eventually reduce the overall application downtime.

But wait, if you are relatively new to phrases like business processes and transactions, then it is better to understand them since they will be constantly used as we dig deeper into the topic.

The business process represents your entire application workflow and will have a group of business transactions that are nothing but a set of activities within a workflow.

Significant Benefits of End-to-end Distributed Tracing

  • You will be able to get a unified view of your message workflow
  • Intuitive dashboards to visualize the correlation between messages
  • Monitor the performance of your business processes in real-time
  • Track every stage in your business flow
  • Resolve business failures before they affect the end-customer
  • Reduce or eliminate the need for manually generating historically based reports

Do Organizations Still Build End-to-end Logging and Tracking Custom Tools?

Application Insights of Azure Monitors does offer a feature called Application Map, which helps you understand the relationship between the distributed Azure Services. Still then, it would be challenging to visualize how your message flows through those services.

When connected with Log Analytics, it is even possible to log the monitored data, but everything is more for individual Azure services and not for an entire application. 

That is why organizations generally build their logging and end-to-end tracing tools for Azure-focused solutions.

But the actual problem is it involves too many manual tasks, requiring an additional workforce, which forces even the Azure developers to write code to develop custom tracking tools instead of letting them focus on developing business applications. That is how third-party monitoring tools became inevitable to avoid the complexities of building custom tools.

There are many options available in the market, and each has its benefits. We will exclusively focus on Serverless360 BAM and how it stands out from the rest.

Serverless360 – A Comprehensive End-to-end Tracking Solution

Serverless360 BAM allows the business users to track, visualize and identify failures in the message flow across the distributed Azure services. Here is an outline of how you can set up tracking in Serverless360 for your applications involving different Azure services.

  • Configure Azure SQL Database and Blob Storage to store the tracked data and the message details.
  • The next step is defining the business processes to visualize their flow and configure the stages in each business transaction to capture the necessary properties
  • Then, instrument your business process for message tracking. You can leverage the custom connectors if you have Logic apps involved in your integration. If there are other services like Custom Apps, Function Apps, APIM, you can track the messages using the .Net library and SDKs from Serverless360.

Serverless360 is all set for tracking your business applications with these quick steps. You can check out their documentation to clarify the above process.

Key Features of Serverless360’s Business Activity Monitoring (BAM)

Visualize Message Flow

Serverless360’s BAM visually represents your business workflows, making it easier to correlate the messages flowing through various Azure services of your complex integrations.

In addition to that, each stage in your message flow will be depicted in different colors indicating their status (success, failure, In-progress, Reprocessed, etc.), so you will spot the failures at a glance.

Serverless360 2

Repair and Reprocess Failed Transactions

Each transaction in your business workflow will be tracked, which helps to identify the root cause and resolve the transaction failures at ease. But, among the many transactions involved, it might be hard to spotlight the failed ones alone. Under such circumstances, Serverless360 brings the faulty transactions in a separate tab, “Action required.”

This way, you can easily segregate the failed transactions, modify the necessary value and reprocess them for a successful resubmission.

Serverless360 3

The platform further supports Bulk reprocessing and Dynamic reprocessing.

Query Search

Serverless360’s BAM lets you fetch business-critical data from many transactions using simple queries, which you can then save, and re-use whenever needed.

Serverless360 5

Out-of-the-box Monitoring Support

Monitor your business processes on various aspects and instantly alert via different notification channels by setting up maximum thresholds. There are two primary monitoring types offered by Serverless360 BAM – Exception Monitoring and Query Monitoring.

Exception Monitoring: Any exceptions occurring within a specified period will trigger an alert. For example, if there are any exceptions within the last 20 minutes, you will be notified.

Serverless360 6

Query Monitoring: This keeps you informed about the performance of your business processes by monitoring them based on different queries. For example, you can choose to get either a warning or an error alert when failures detected within a specific time duration reaches the threshold limit.

Serverless360 7

There is also an alert history tab, which lists all the alerts generated by Query and Exception Monitoring so that you can view all the alert details and figure out the failed ones.

Dashboard

You can view and analyze the tracked data using Serverless360 BAM’s real-time dashboard, which gives you a visual representation of the data in charts and reports. You can quickly detect anomalies and visualize data trends that can help take appropriate corrective measures.

Below is an example of Serverless360’s BAM dashboard, allowing you to instantly see when there is a spike in failed transactions to find out what the problem is and fix it.

Serverless360 8

Conclusion

As mentioned above, in a real-time business scenario, any Azure or hybrid application will incorporate several services, making it difficult to visualize the flow of messages. In this blog, we discussed how Serverless360 BAM (15-day free trial) could be used to achieve end-to-end visibility, visualize message flow, monitor business processes, detect failures, perform root cause analysis – all in a single platform. Further explained how distributed tracing can be helpful and why using third-party BAM tools can be more effective than building custom tracking tools.

The post Serverless360 – Ultimate Solution for All Custom Logging and Tracking Needs appeared first on The Crazy Programmer.



from The Crazy Programmer https://ift.tt/OeJ9uFi

The email validation system, known as DMARC (Domain-based Message Authentication, Reporting, and Conformance), is meant to safeguard your company’s email domain from being exploited for phishing, email spoofing, and other cybercrimes.

For email authentication, DMARC records use SPF and DKIM. With DMARC, you can do reporting, which is a critical feature. By publishing a DMARC record in their domain’s DNS, domain owners may see who is sending emails on their behalf.

Using this information, you may receive further information about the email channel. A domain owner may take control of the email sent on his behalf using this information. Your domain may be protected against phishing and spoofing attacks by using DMARC.

You, as the owner of a website, want to be certain that only emails that you have sent will be seen by your visitors or customers. As a result, DMARC is a must for all domain registrants.

DMARC provides email recipients with the assurance that an email they receive from you is authentic and has come from you. In addition to improving email delivery, this prohibits others from utilizing your domain to send emails.

DMARC: A Brief History

In 2012, the DMARC standard was issued for the first time in an attempt to stop email misuse. The DMARC standard was produced by PayPal, Google, Microsoft, and Yahoo! in collaboration with each other.

In order to acquire official standard status, these industry experts joined together to produce an operational specification. The DMARC standard was built on the SPF (Sender Policy Framework) and DKIM (DomainKeys Interoperability Markup Language) authentication methods (Domain Keys Identified Mail).

At its inception, the DMARC system was designed to protect email communications. DMARC was first accepted mostly by finance sector security specialists. Since then, the use of DMARC has grown and expanded throughout the internet. DMARC is becoming more and more accepted by email marketers as a means of enhancing internet security and enhancing email delivery.

All major Internet service providers (ISPs) presently support DMARC. DMARC is now in the process of being accepted as an open standard by the Internet Engineering Task Force (IETF).

What is the Purpose of DMARC?

The email channel has the widest reach as compared to any other medium, with about 5 billion global email accounts. As a result, cyber thieves have a strong interest in using this route for their nefarious activities. Despite increased security measures in previous years, criminality on this channel continues to rise each year. Most hacking and data breaches occur via email.

In this context, domain-based authentication reporting and compliance (DMARC) is a valuable tool for organizations. DMARC makes phishing assaults transparent as well as providing comprehensive visibility into email channels. 

DMARC is more powerful: DMARC can mitigate the effect of phishing and malware assaults, prevent spoofing, guard against brand misuse, frauds, and prevent corporate email penetration. DMARC Analyzer makes it easier for organizations to implement DMARC and streamlines that process.

What can DMARC Accomplish For You?

DMARC can protect organizations and their clients against malicious emails sent on their behalf. DMARC provides an organization with access to its email channel’s information. Organizations may use this information to develop and enforce a DMARC policy.

Rejection of DMARC policy to reject protects companies from:

  • Customers of the organization are being phished.
  • Scams and misuse of a well-known brand
  • Ransomware and Malware assaults
  • Employees are at risk of falling victim to spear phishing and CEO fraud.

DMARC Analyzer provides enterprises with a comprehensive view of their email channel. DMARC’s ability to obtain complete visibility into the email channel is a major benefit since companies previously only had access to phishing assaults after they had already occurred. With DMARC, phishing attempts may be analyzed and prevented. As a result, clients are more prepared and aware of these threats.

When it comes to email fraud detection, DMARC is the most important tool in the toolbox. Phishing schemes, such as those that send emails on behalf of banks using legitimate-looking websites, are an example. In the minds of customers of that bank, an email claiming that their bank card is no longer valid is a legitimate one. 

The link you’re about to click will take you to a shady website. Logging on to this website, which is a perfect replica of the genuine thing, will provide hackers access to your credentials.

The post The Importance of Having Proper DMARC Records appeared first on The Crazy Programmer.



from The Crazy Programmer https://ift.tt/OyTZBSC

Currently, the HTML editor Windows has already undergone many developments. But with all these changes, there are still many people who do not know about the secrets of HTML editors for this operating system.

If you are one of them, then this article is for you. Here, we will tell you the best-kept secrets about HTML editors for Windows that will make your life easier.

The best part is that there is no need to install any software besides your current HTML editor to use these secret features. Many HTML editors for Windows have these hidden features built-in that make them far more valuable than a simple text editor.

But before we go ahead and tell you all about them, let’s look at some of the reasons why you should use an HTML editor for Windows.

What is an HTML Editor And Why Should You Use It?

HTML editor is an application that helps you create, edit, and publish your website. It supports all major web browsers and works with any Windows computer. You can use an HTML editor to create and edit web pages, online forms, and HTML documents.

The most important feature of this program is that it enables you to create your own website. An HTML editor allows you to publish your website on the web or local intranet with one click. You can also use it to compose file types such as PDF files, presentations, e-books, and any other printable encoding format.

What are the Best Kept Secrets of HTML Editors for Windows?

The Best Kept Secrets About Html Editors For Windows

1. Text Editor

HTML editors can easily take on the role of your text editor. With an advanced text editor in your hands, it will be much easier to write your own content or edit blog post written by others on your website.

Plus, there are many advanced features in HTML editors for Windows that can help make your work easier than ever before. These advanced features include undoing changes, adding links, comments, and inserting other code such as Inline Frames (IFrames) and Cascading Style Sheets (CSS).

HTML editors also have a preview feature, so you can also view your HTML document in a more “human-readable format”, meaning you can see the result of your editing with ease and fix your mistakes in advance.

2. Page Navigation

A common problem that arises when you are working on a website is the problem of page navigation format.

With an HTML editor for Windows, you can quickly and easily navigate through the different pages of your website. This makes it easy to go back to a previous page or go forward to a new page on your website.

An HTML editor for Windows also gives you the ability to copy text from one page to another or even copy the entire source code and style attribute of one page and paste it into another.

3. Build Basic and Advanced Websites

It is possible to build basic and advanced websites with a dynamic HTML editor for Windows. In addition to basic tasks like building web pages, you can also perform more advanced functions like managing contact forms, managing databases, and creating complex websites.

4. Easy to Learn

HTML editors for Windows are easy to learn and a great choice for both beginners and advanced users. Usually, they have WYSIWYG (What You See Is What You Get) web editor mode that is perfect for HTML beginners.

The interface of many HTML editors is also very easy to understand which makes it a piece of cake for people who are new to web designing or web development.

It also has a learning mode that allows you to take a look at how the interface works before you start using it. This makes it easier for you to learn how the interface works before you start editing the configuration values of your project file.

5. Advanced Design Features

HTML editors for Windows have advanced design features that can help you create even better websites.

A few of these features to explore are:

  • Creating an unlimited number of columns
  • Table and content formatting
  • Drag and drop functionality
  • Live previewing of content
  • Importing and exporting templates
  • Exporting HTML as a CSS (Cascading Style Sheets) file or as a JavaScript file

Once you have a grasp on the common features, you can also explore some more advanced features such as changing the page layout on the fly, adding comments to your website, working with multiple templates on one page, and many more.

These advanced features can help you create better websites than ever before.

6. Multi-Platform Support and Efficiency

Most HTML editors support multiple platforms such as Windows, Mac OS X, and Linux. This makes it easier for you to work on your website in the best way possible no matter what operating system you are using on any given day.

Command-line tools are also available with most HTML editors for Windows that allow you to work on your website in a much more efficient way.

7. Support for Plug-Ins

With an HTML editor for Windows, you can easily install plug-ins to make building and editing your web pages faster. Common choices are a spelling checker plug-in or an image insertion plug-in. This makes it easy for you to use the most advanced features that these plug-ins have to offer.

Source control systems such as Apache Subversion and GitHub are also supported. Many websites like Amazon and WordPress use source control systems to keep track of code changes on their websites.

8. High Compatibility

Configuration file compatibility varies between editors. Most of the tools in this category allow you to edit both CSS and HTML code at the same time. Most of them are useful in both Windows and Mac OS X operating systems.

The choice is up to you. Most HTML editors for Windows are compatible with other popular web browsers and for Internet Explorer versions earlier than version 9.

HTML editors are designed for editing code, but they can also be used for creating graphics, presentations, and even video clips with ease.

9. Fast and Reliable

Most HTML editors for Windows are fast and reliable. When you type a standard input, the text will display in a few seconds. These are also available for different types of documents such as emails, articles, forms, and more.

These editors can save you time and prevent you from having to write the same content again and again.

10. Easily Maintainable

With an HTML editor for Windows, you can easily maintain your website. This is because of the advanced features that these editors have to offer. You can easily make updates to your website by simply editing the source code and making changes to it in a very short time.

The security properties file that these editors offer is one of the best features. This is because you can easily make changes to your website without any worry about the possibility of any hacker making unauthorized changes to your website.

11. Multimedia Support

If you use an HTML editor for Windows, you can easily create multimedia like flash movies and animated gifs. You can also use the advanced features that these editors provide.

The project tree in HTML editors for Windows provides you with a comprehensive tree view of all the files. You can also select multiple files at once and copy, paste, or delete them.

12. Full Source Code Viewer

Full Source Code Viewer (FSCV) is a great tool that allows you to open and edit the source code of any web page. With this tool, you can edit your own web pages easily and quickly.

In addition, it has the capability to show all the cross-references and references in the file. This means that you can easily find what you are looking for in the source code of any web page.

Moreover, it supports syntax highlighting for HTML files and other markup languages like XHTML, XML, CSS, JavaScript and VBScript. With this tool, you can also save your edited files as HTML files for viewing on your computer or for sending to others by email.

It also has a spell checker that helps you correct mistakes in your source code. You can also preview pages as they will appear when viewed by others with this tool.

13. Image Compression

With an HTML editor for Windows, you can easily compress images to save space on your website.

Image compression is important because it allows you to reduce the amount of bandwidth that your website uses. Especially, if you have a large number of images on your website, you can use an HTML editor for Windows to reduce the size of images that your website needs to load. Having a fast load time is an essential component of any successful website.

14. Image Transfers

Image transfers are important to make a great presentation on your website. Many websites are now using image transfers to get a great look. This image transfer will be a great part of your website and it will make it look more professional.

How does it work? It will work on your website if you have proper web hosting. It will give you the right amount of speed so that your site can load quickly.

The file path will be automatically added to your website and you will not have to worry about it. The best thing about this is that it will work for all browsers and operating systems.

Ready to get started with a powerful HTML editor for Windows?

In this article, we have discussed the best-kept secrets about HTML editors for Windows. Hopefully, you will find this article useful and will be able to get a better idea about HTML editors for Windows.

UltraEdit is the most advanced HTML editor for Windows. It has a lot of advanced features that can help you to create and edit your website’s code. If you are interested in trying out these advanced features, download UltraEdit now!

The post The Best Kept Secrets About Html Editors For Windows appeared first on The Crazy Programmer.



from The Crazy Programmer https://ift.tt/VgTk3CP

In our daily life, we often write some big programs and some small level programs to solve the different problems. Whenever we try to solve a complex level problem, then we have to write so many lines of code.

In that code, we often use different types of loops like for, while, or any conditional statements like if, if-else or if-elif-else.

Sometimes we have to write the whole loop to process a single statement in the loop or a minimum of two or three statements. When we write this in our code it generally takes approx 4 to 5 lines to complete a general for loop in which we have to perform a single operation.

Case 1:

For example, I am showing you the code where we are trying to print whole numbers upto 5.

for i in range(5):
    print(i)

Output:

PS C : \ Users \ ASUS \ Desktop \ TheCrazyProgrammer Work > python -u " c : \ Users \ ASUS \ Desktop \ TheCrazyProgrammer Work \ test.py "
0
1
2
3
4

As we can see in the loop we are only printing the i value, it takes 2 lines to complete the loop and execute it.

If we want to process 2 or 3 statements in a loop, python allows us to do it in a single line only.

It is also called single liners in python. We can use a single line for loop to write the same program in less numbers of spaces. Although sometimes it increases the readability but if you are experienced with it then you will find it useful.

Now let’s see the one liner for the above example.

for i in range(5): print(i)

In the above example, we can see that we have written the same code in a single line only.

These single liners can be useful to quickly write a task in which we simply want to perform one or two operations.

Case 2:

In the above examples, we have seen how to write one liner for loop in which we have to perform a single operation. Now we will see how to write one liner for loop in which we have to perform some complex operations.

Let’s see the example where we are going to use a for loop and we will be using some if else conditions in that loop.

First, we will see how to write it in a traditional way, after that we will see how to write it in one liner way.

for i in range(10):
    if (i < 5):
        j = i ** 2
    else:
        j = 0
    print(j)

Output:

PS C : \ Users \ ASUS \ Desktop \ TheCrazyProgrammer Work > python -u " c : \ Users \ ASUS \ Desktop \ TheCrazyProgrammer Work \ test.py "
0
1
4
9
16
0
0
0
0
0

In this example, we are trying to print the square value of i when it is less than 5.

If it is greater than 5 then we simply print 0. As we can see in the example to write code for this problem, we use 6 lines to complete it. But using one liner we can complete it in a single line only.

for i in range(10): print(i**2 if i < 5 else 0)

We will get the same output in both of the cases. In one case we have written the code in 6 lines and in the second case we have written the code in 1 line only.

Although for a beginner I will recommend going with the traditional option only because as a beginner there will be some difficulty in understanding one liner.

The post Python One Line for Loop appeared first on The Crazy Programmer.



from The Crazy Programmer https://ift.tt/kdRIbJG

We know that in many languages like C, C++, Java, when we want to use any variable then first we have to declare that variable and after that, we can use that variable in our program.

The languages listed above are high-level languages that are compiled before it runs, but Python is a dynamically compiled language. In python, we don’t have to specify which type of variable we are going to use. Simply we have to write the name of a variable and we can use it as per our own like we can store an integer value or a string value in the same variable.

So the question comes, is it possible to declare a variable without value in python?

The answer is no, we cannot declare a variable without value in python. I will demonstrate an example to prove my point.

Let us see a basic addition of 2 numbers program in Python.

num1 = int ( input ( " Enter Number 1 : " ) )
num2 = int ( input( " Enter Number 2 : " ) )

print ( f " Sum is { num1 + num2 } " )

Output:

PS C : \ Users \ ASUS \ Desktop \ TheCrazyProgrammer Work > python -u " c : \ Users \ ASUS \ Desktop \ TheCrazyProgrammer Work \ test.py "
Enter Number 1 : 32
Enter Number 2 : 5
Sum is 37

Here, we are directly using the variable without declaring anything previously, because as python is a dynamic language it allows variables to be created at run time.

Now, we are going to see an example in which we will not assign any value to the variable in python, and let’s see the output in that case.

val

for i in range ( 10 ) :
    if ( val == None and i == 5 ) :
        print ( " I am in the if Block " )
    print ( i )

When we run this program then we will get an error.

Output:

PS C : \ Users \ ASUS \ Desktop \ TheCrazyProgrammer Work > python -u " c : \ Users \ ASUS \ Desktop \ TheCrazyProgrammer Work \ test.py "
Traceback ( most recent call last ) :
  File " c : \ Users \ ASUS \ Desktop \ TheCrazyProgrammer Work \ test.py " , line 47 , in < module >
    val
NameError : name ' val ' is not defined

We got NameError which tells us that the name of the variable we have used in our program is not defined.

We have not defined any value of that variable so the interpreter is not able to recognize the variable and it throws an error.

Python Declare Variable Without Value

We are going to see a trick to initialize any variable without a value, actually, this is not a trick but a way to initialize a variable when we do not want any value to set up at declaration time.

We can do it by setting the value of the variable to None.

We will modify our previous code to that it will be executed successfully.

val = None

for i in range ( 10 ) :
    if ( val == None and i == 5 ) : 
        print( " I am in the if Block " )
    print ( i )

Output:

PS C : \ Users \ ASUS \ Desktop \ TheCrazyProgrammer Work > python - u " c : \ Users \ ASUS \ Desktop \ TheCrazyProgrammer Work \ test.py "
0
1
2
3
4
I am in the if Block
5
6
7
8
9

We can see that our program is executed successfully.

In python, we cannot declare a variable without any value because python is a dynamic language and it does not allow variable without value. In python it is not necessary to declare the datatype of the variable, we can directly use the variable in our programs.

The post Python Declare Variable Without Value appeared first on The Crazy Programmer.



from The Crazy Programmer https://ift.tt/7ySszFQ

A database system is a very huge and complex application. To understand the complete structure of a database we should divide it into small modules. Let’s discuss them one by one in detail.

Users

Those who interact with the database. On the basis of how they use the database we can divide them into three categories:

  • DBA: Database administrator have full control on database. They may be a group of persons or a single person. They use Data Definition Language to pass on schemas and mapping constraints on database, which further passed to DDL processor.
  • Users: These are end users who actually use database for their own purposes. They pass queries with the help of interface system provided. These queries further passed on to the Queries processor.
  • Programmers: These are the persons who actually creates database and manages it technically. They use Data Manipulation Language statements to pass on application programs to database, which further goes to DML processor.

The Query Processor

In this section all the high level or user level commands, queries and statements are compiled or interpreted into low level language for further execution and storage.

Processors: These processors execute the different types of queries passed to them. As per the type of queries and statements passed on, we have three types of processors as per given below:

  • DDL Processor: These compile the data definition language statements passed by DBA and also convert the system generated output to the DDL statements for understanding of DBA. These are further divided in two segments as per given below:
    1. DDL Statement: Identify the DDL statements and convert them into the low-level language understandable to the data dictionary for further execution.
    2. DDL Compiler: Receive the data from DDL statements and compile them so that they can be executed by further processes.
  • Queries Processor: These compile the queries passed by end users and also convert the system generated output to the natural language for understanding of End users. These are further divided in two segments as per given below:
    1. Interactive Query: identify the Queries and convert them into the low-level language understandable to the data dictionary for further execution.
    2. Query Compiler: receive the data from Interactive Query and compile them so that they can be executed by further processes.
  • DML Processor: These compile the queries passed by application programmers and also convert the system generated output to the DML statements for understanding of Programmers. These are further divided in two segments as per given below:
    1. DML Statement: identify the DML statements and convert them into the low level language understandable to the data dictionary for further execution.
    2. DML Compiler: It compiled or translate the DML statements received by End users or programmers into a query language. This query language is consisting of low-level language so that query evaluation engine can understand it, execute it and performed the required or desired operation.
  • Query Evaluation Engine: This is the actual processor which executes all the translated or interpreted low level commands or queries received from above mentioned processors.
  • Embedded DML pre-compiler: It received the application embedded DML statements and converts them to normal procedure calls in the host language used. Also, the pre-compiler interacts with DML compiler to generate the appropriate code to remove conflicts.
  • DDL Interpreter: It interprets DDL statements and saves the data definitions in the data dictionary for further records.

Storage Manager

This is a specific program module that provides the interface between the low-level data stored in the database and the application programs along with the queries passed to the system by users or other processes of the database. It provides the interaction with the file manager and manages all storage available and try to optimize the use of storage. The further parts of the storage manager are as given below:

  • Data Dictionary: It stored meta data, means data about data. It helps the overall system to identify the data type received or generated. It’s also helps to separate the schemas data language, interactive queries passed by end user and the DML statements or application programs for better understanding of system and smooth functioning.
  • Authorization and Integrity Manager: As name implies its checks and allot the authority of the user and manages the integrity constraints applied on database.
  • Command Processor: Execute the commands received from the compilers.
  • Query Optimizer: This optimize the queries so that these queries can be processed in the minimum resource utilization.
  • Transaction Manager: It manages the over all transactions performed in the complete system for smooth and conflict free experience. Also, it ensures that the database should be remain in consistent state because each and every transaction affects the database.  
  • Scheduler: As name implies it schedules all the tasks in the system including queries execution and transaction management.
  • File Manager: It is responsible for allocation of space on disk storage and also manages data structures and techniques used in representation of the information stored on the disk.
  • Buffer Manager: This manages and controls that how the required data maybe fetched from storage and transferred to the main memory. Also manages the reverse operation as well.
  • Recovery Manager: It is like backup and restore option. All the operations and transactions and all the changes made are going through this section so that it can keep track and record of all these activities. So that whenever required it can provide the backup or roll back the operations.
  • Physical Database: This is actual physical storage where all the low level or real data is stored. This can only save the data and transfer it when ordered.

Disk Storage

This manages the overall storage available. This can be further divided into these below sections:

  • Data Files: It is actually the stored data. A data file is a storage block or bucket in which data can be stored. Data files have variable sizes.
  • Data Dictionary: It stores the data about data. Means what data is stored where at which time and how to reach there.
  • Indices: This works as a up to date index of all data items. It helps to fast access to all these data items.
  • Statical Data: As name implies it stores the statical information about any data present in database.

The post Overall Structure of DBMS appeared first on The Crazy Programmer.



from The Crazy Programmer https://ift.tt/skVul5F

Running a computer program takes some time to complete. If it is a big task then it can take more time and if it is a small task then it will take less time to complete.

For example, let’s consider our operating system and an application called WhatsApp which is a social media platform for communication. We all know that when we start an operating system then it takes some time to completely boot it up. Because an operating system consists of so many heavy tasks and programs, booting up means getting everything ready to work.

An application takes so much less time than an operating system because the application is not consisting the big tasks like an operating system.

How to Measure Execution Time in Python?

If we have written a program and we want to know the time which it takes to execute, then we can know the exact time duration by using some methods in python language.

We can perform this task by using the time module, which is an inbuilt module in python.

Example 1

from time import time

# We have Created a Function to find sum of First 1000000 Numbers
def first_func () :
    # Initialise the sum with 0
    sum = 0

    # loop through 0 to 1000000 and add previous value of sum to it and get the updated sum
    for i in range ( 1000000 ) :
        sum += i

    # return the sum value
    return sum

if __name__ == '__main__':
    init = time ( )
    ans = first_func ( )
    final = time ( )
    print ( f " Time Taken : { final – init } " )

Output:

PS C : \ Users \ ASUS \ Desktop \ TheCrazyProgrammer Work> python -u " c : \ Users \ ASUS \ Desktop  \ TheCrazyProgrammer Work \ test.py "
Time Taken : 0.05800580978393555

Explanation:

As we can see in the example above, we are going to find sum of first 100000 whole numbers using python.

First, we have imported time function from time module. After that we have written a function to calculate the desired sum. We have initialized sum with 0. After that we have used loop to iterate through 0 to 100000 and update the sum value with I and previous sum value, after the loop ends, we have returned the sum.

Now, coming to main function, we have init variable which holds the value of time at the particular time. After that we have called our function to calculate the sum.

Now we have stored the current time in variable name final.

As we can see that we are executing that function and calculated time before executing the function and after executing the function, then we can find the duration to run this program by subtracting the final value from initial value.

This gives time to execute the function.

Example 2

from time import time

# We have Created a Function to find multiplication of first 100000 natural numbers
def func ( ) :
    # Initialise the mult with 1
    mult = 1

    # loop through 0 to 1000 and multiply the previous value of mult with i and get the updated value
    for i in range ( 100000 ) :
        mult *= i

    # return the mult value
    return mult

if __name__ == '__main__':
    prev = time ( )
    ans = func ( )
    updated = time ( )
    print ( f " Time Taken : { updated – prev } " )

Output:

PS C : \ Users \ ASUS \ Desktop \ TheCrazyProgrammer Work > python -u " c : \ Users \ ASUS \ Desktop \ TheCrazyProgrammer Work \ test.py "
Time Taken : 0.005994319915771484

Conclusion

We can measure the execution time of any program using the time module, which is an inbuilt module in python. We can find the execution time using some basic logical operations as I have shown in the above examples.

The post Python Measure Execution Time of Function appeared first on The Crazy Programmer.



from The Crazy Programmer https://ift.tt/QAlpe8L

Can a well-optimized site have an attractive design? High-quality text content, relevant keywords, competent internal linking, and backlinks from authoritative sites – all this helps to promote Internet resources. However, what about design? Many people focus on SEO optimization, forgetting that visitors come to the site, and for them, the design of the resource plays an essential role. So can we combine SEO and website design to get an SEO-friendly beautiful design of your site? If so, what will such an “ideal” website design with SEO look like? Let’s take a look at some examples.

​​As you already know, having an online presence is a must for today’s businesses. If you want to stay competitive and ensure people find your brand when searching, you can not avoid this step and should build a website.

What is Website Design with SEO?

One can name many arguments proving that SEO and web design as allies in creating a unique website. For a good site, it is essential to use off-page optimization and a sufficient amount of backlinks, etc. If the site has well-thought-out web design SEO, it improves its position, and you apply backlink indexing service to get the top position in Google ranking faster. Using SEO in web development and integrating these SEO strategies into your web design process will improve the indexing process and help your site rank higher in SERPs (Search Engine Result Pages).

The Key to Balance between SEO and Website Design

How to Find a Balance Between SEO and Web Design?

High-quality websites are those trying to find the right balance between SEO and graphic design. Such websites are characterized by pretty good external and internal optimization (internal linking, structured text containing helpful information for visitors, etc.). In terms of design, these sites are quite informative. Disc photos are the dominant element on each page, visually highlighting its most important parts and improving the perception of information as a whole. At the same time, the application of the “rule of thirds” is visible in web design.

Following experts’ recommendations, it is quite easy to achieve the optimal balance between SEO and website design. Now, let’s have a look at a list of the best actionable recommendations:

1. Simultaneity

In the initial phase of your website’s creation, start thinking about its optimization for the search engines. When choosing keywords or phrases, try to imagine how they can be integrated into the design: from text, tags to code. Keywords added in the form of graphical elements after the design is completed can break the integrity of the perception of the entire site.

2. The Principle of KISS (keep it simple, stupid)

Today, to develop a really good site, it is not more necessary to use fancy graphic elements (of course, if you are not doing a web project for yourself and aiming to demonstrate your talent to everyone in this way). As you know, people don’t get excited about sites designed in a flash or containing fancy applications. In addition, the use of Flash technology “slows down” the page loading, which is especially annoying for the clients who need to get info quickly. Another plus in favor of a simple design is the location of the search engines. Websites with a simple design are easier to optimize and promote in TOP.

If you still decide that you can’t do without a flash, follow these rules:

  • do not include important content in a flash;
  • do not use flash technologies to create site navigation;
  • do not place the entire web project on one page.

3. Good Web Design Attracts Links

An important part of the SEO optimization process is gathering backlinks on other Internet resources. Good design attracts Internet users and increases their trust in the site. Want to get external links to a web project? Send the developed resource to special exhibitions. For example, you can place it in one of the CSS site galleries (cssnature.org, bestwebgallery.com, etc.). Important links from external resources can be placed in the footer. At the same time, the footer does not have to look gray and boring.

4. Friendly Scripts

When using technologies such as JavaScript, you need to be careful. Javascript allows you to create a wide variety of effects, but any mistake made when using this technology can lead to many problems. It is traditionally believed that search engines cannot process javascript requests, resulting in content even with professional editing not being recognized or indexed. jQuery can be an alternative to JavaScript. Firstly, it allows you to create links for search engines. Secondly, it gives you the possibility to create impressive visual effects.

5. Modern Navigation

High-quality SEO and website design require a clear website structure. It is worth abandoning uncomfortable menus containing sub-items of the third level and return systems using the “Back” button. Instead, it is more expedient to implement a journey through the site’s pages on the “breadcrumb” or breadcrumb navigation.

Conclusions

Summing up, web design SEO is essential. When we invest in developing a good site, we want it to be highly presentable and SEO friendly, with pleasing visuals and offer functional, simple, and intuitive navigation. In the conditions of high online competition, SEO optimization and the website design are equally important. At the same time, you should not focus on one thing. A healthy combination of good SEO and good design is the key to online campaign success.

Author Bio:

Frank Hamilton is a blogger and translator from Manchester. He is a professional writing expert in such topics as blogging, digital marketing and SEO. He also loves traveling and speaks Spanish, French, German and English.

The post How to Find a Balance Between SEO and Web Design? appeared first on The Crazy Programmer.



from The Crazy Programmer https://ift.tt/7HM9D3p

There has been a tremendous shift in how we watch television and read newspapers for the last years. These days many people prefer getting instant news updates online. The best part is many people are now turning to the internet as an essential source of current information. It is pretty clear, online content and news are the big business today.

The question is: where does this content come from? It is pretty simple to answer:

Suppose you do not wish to create news content but just want to furnish relevant, dependable, and real-time headlines, then you need a media news data API.

The best API you can pair with news API is mediastack. If you’re looking for a content API, then mediastack API is the best option today. But how does it work, and what are the critical things you need to know?

This post will look at the basics, essential features, and plans and understand why MediaStack is an obvious choice for your requirements.

Mediastack Review

Basics of Mediastack

Mediastack works in a simple to use and robust REST API interface, which collects news and various blog articles from different sources across the world.

It provides news content you want within a second through its lightweight JSON format.

News data gets refreshed every minute and is available with different categories like education, sports, entertainment, business, and more.

mediastack is owned by APILayer for providing a wide range of microservice APIs, which run more than 15 data APIs. Most of them include currency conversion, aviation data, IP address geolocation, and stock market data.

They are an international leader used by many innovative firms worldwide, like LinkedIn, Lyft, and Airbnb.

How Does Mediastack Work?

Getting started with the mediastack couldn’t be easier, and there is a free plan, which is enough to prototype the project.

Complete documentation is provided with the code examples for Python, PHP, Go, jQuery, and Ruby. To go ahead, you have to register for the free access key.

When you have the free access key and connect to API, you can customize the results that you get with the simple parameters.

You may specify types of news, authentic sources (that includes omitting sources), countries, languages, and your keywords.

You have to sign up to get the API key. It is free for the first 500 requests per month to prototype what you are building, mainly if you are brilliant at caching reactions.

Then, when you want more requests, this scales up reasonably in the price.

Important Features of Mediastack 

  • You get access to more than 7,500 global news publishers & blogs from over 50 different countries in 13 languages.
  • You can track breaking events with the latest news updates every minute.
  • Data transmitted in the most organized & readable format
  • Get access to the data from leading and popular news sources such as NY Times, CNN, Euro News, MSNBC, ESPN, Guardian, BBC, Al Jazeera, and more.
  • Scalable API cloud infrastructure & offers news results in the straightforward and lightweight JSON format.
  • Get access to the historical & real-time news updates. 
  • Secured data delivery. They offer data by using 256-bit HTTPS encryption.
  • Choose the news sources hence you do not get inundated with any insignificant news.
  • Filter news via languages, countries, keywords, and categories
  • Detailed and simple to use documentation hence anybody can use it

Besides the given features, they also have a free plan that does not need you to enter the payment details.

Final Thoughts 

Mediastack News API was made to be very powerful yet easy to use and scalable while delivering real-time live data worldwide.

This REST API makes it very simple to collect & understand data as it is coming in the JSON format. 

Thus, it is pretty intuitive and simple, basically providing you with news content without any issue.

If it is something you are interested in, you must check out mediastack. Sign up for their free package & test it yourself.

The post Mediastack Review – Be Always Up-To-Date With a Real-Time News API appeared first on The Crazy Programmer.



from The Crazy Programmer https://ift.tt/gzCGWBu

Web hosting is serious business, and if you are new to the game, getting your website up and running on the Internet can come with all sorts of unique challenges. The established industry standards like dedicated or shared web hosting are hard to ignore. Even the latest addition to the team – cloud computing – has a hidden allure that’s hard to resist, especially if you like to test the latest technologies offered.

However, if you are looking for the best mix of flexibility and power, there is no better option on the market than using VPS hosting.

Why so? What makes VPS hosting so special?

Hand on, we’ll soon give you the answer to these questions. We’ll talk about VPS hosting, how it works, and the main benefits of using it.

VPS Hosting

What is VPS Hosting?

First, let’s get the basics out of the way.

VPS stands for Virtual Private Server, which in short, means an isolated environment on a server machine that’s created using virtualization technology.

Since it’s software-based, it can be configured to function as a dedicated physical server for web hosting, with its own set of dedicated resources.

You’ll still be technically sharing resources with other users on the central server, but you’ll reap the benefits of having complete control over your private server. VPS hosting offers you the freedom to change and customize any aspect of the server freely.

Unfortunately, you’ll need to have advanced technical knowledge to do this. Luckily, hosting providers are a step ahead, so they provide plans for end-consumers who lack the skills needed to manage a server. These packages offer dedicated support from an experienced web administrator who will cater to your needs.

What is VPS Hosting Used for?

There’s not a lot you can’t do with a sufficiently powerful VPS hosting. VPS hosting allows for creating and realizing any big project way past its conception stage.

It is powering huge eCommerce websites that have thousands of daily customers all actress the globe—maintaining enormous email servers that feature an unlimited number of inboxes and users, housing complex databases for any demanding application. The list is practically endless. These are just some of the examples that come to mind.

VPS hosting is full of possibilities for anyone looking for dedicated and reliable web hosting that’s flexible and has top-notch performance.

VPS Hosting Advantages

VPS hosting is the ideal framework for any website compared to other web hosting types on the market.

As we mentioned, a VPS runs in an isolated environment, with its share of computing power and resources. This hosting model brings many benefits to the user, some of which are covered in the list below.

Stability for High Traffic Websites

With shared hosting, you share the same resources with many other users on the network. If a big traffic spike occurs, guilty or not, your own website will slow down, or even worse – In the case of a server crash, it can become completely inaccessible. That’s not something you want, especially if you manage a successful business. on the other hand, With VPS hosting, fluctuations in the web connection won’t affect you.

It’s Entirely Scalable for Any Size

Eventually, you’ll hit your web hosting limit, and when that happens, you’ll have to go through the hassle of transferring your website to another hosting and another server. And only then can you upgrade to a plan that suits your needs. In contrast, VPS hosting can be scaled to any size, personal, entrepreneurial, corporate, or industrial.

Much Faster When Compared to Competitors

Network speed is the game’s name when it comes to web hosting. With VPS hosting, not only do you get to have a stable disruption-free connection, but you also get the pleasure of having it at breakneck speeds. All of your visitors can enjoy lightning-fast loading times.

Access to the Root Directory

With VPS hosting, you can access the innermost directory of your remote server. This way, you have a full range of control over all the key components of the server. In other words, installing custom software or modules, modifying internal configurations, changing the way running apps interact, doing a personalized system restart are only a few examples of the functionality that comes bundled up with a standard VPS hosting plan.

Security 

Anyone who plans to share, host, or manage confidential data on the web, sooner or later, will encounter the threat of a data breach. This is especially important for enterprises. Data breaches are the easiest way to lose your customers’ trust and concurrently your profit. The best way to resolve this issue is to build a stable foundation capable of bouncing back from any danger or setback. When you use VPS hosting, your website runs in an isolated and safe environment – a safebox, so to speak – so your data will be well protected from harm even in the case of a server crash.

Bigger Storage Space and Larger Bandwidth

VPS plans are usually centered around enterprises and large to medium businesses requiring content upkeep and large traffic. That’s why VPS plans come prepacked with a sizable set of bandwidth and storage. Not only that, the allocated server space is dedicated to only to your virtual machine, thus making it faster and better.

You Get Excellent Customer Support

VPS hosting providers mean business. And they play for the long game. So chances are, you get to benefit from having premium support. 24/7 on-call assistance is excellent, plus you enjoy the feeling of being valued as a customer.

Sturdier Server Infrastructure

VPS hosting servers usually use up-to-date hardware that’s been proven to work reliably and efficiently. That means you get a large amount of RAM, a current-gen CPU, and your remote machine is guaranteed to use the latest OS. Plus, you get to enjoy an excellent uptime percentage. And what’s better, these resources are only dedicated to your demands.

VPS Hosting Disadvantages

Expensive

VPS is doubtlessly the more expensive option compared to shared web hosting. If you think you can manage with a cheaper option, or if your website lacks the need for high-end web hosting, a VPS might not be the most suitable choice.

It Requires More Technical Knowledge to Get the Most Benefits

VPS plans usually feature some sort of user-friendly control panel. But, it’s often limited in its capabilities. So, if you are a beginner on the technical front, you might get more for your buck choosing different hosting solutions.

VPS Hosts That do Offer a Management Service are More Expensive

VPS providers are usually self-managed. In other terms, that means you’ll have to do all the work by yourself. A simple solution is to hire an in-house web server expert who’ll ensure you get the proper configuration for security, monitoring, and performance. Unfortunately, you have to pay extra cash if you plan to use this feature.

Summing Up

VPS is a high-performance solution for anyone searching for a powerful web set-up that has the capabilities to be scalable in the future.

It’s mainly targeted at developers, designers, or system administrators – pretty much anyone who has in-depth knowledge of managing a complex webserver.

However, if you are keen on taking advantage of everything this type of hosting offers but don’t have a technical background, taking a managed VPS plan is the way to go.

The post VPS Hosting – Uses, Advantages, and Disadvantages appeared first on The Crazy Programmer.



from The Crazy Programmer https://ift.tt/xurIAsG

Battling with any type of error during developing something gives a large amount of frustration. In python, we can encounter many types of error which can be easy to recognize or sometimes it can be very hard to recognize.

So today we are going to see a common type of error in python which is very difficult to get recognized sometimes. Because these errors cannot be recognized with some basic debugger tools because, in the sense of logic, your program will be correct everywhere.

Today we will discuss a common Type error named cannot multiply sequence by non-int of type ‘float’. We will see what are the causes of this error and what can be possible solutions for this error. We will see two different cases of occurring of this error and we will see the approach to find and solve this type of error in our programs.

First, we will see what ‘sequence’ means in this error?

In python, Strings, list, tuple or sets etc. are known as sequence.

When we try to perform some operations using any of the sequences from lists, tuples, strings or sets, and we do some mistakes in performing those operations then we will encounter this type of error.

Now let’s see some cases in which this error can occur.

Reasons for Error

Case 1:

Assume that you are writing a program that calculates the area of the circle. In this case radius of the circle is taken as an input from the user.

You have written the code like this.

radius = input (" Enter Radius : ")

area = 3.14 * radius * radius
print (f " Area is {area} ")

When you run your code in the terminal, then you will see the output in the terminal as follows.

Output:

PS C:\Users\ASUS\Desktop\Geeksgyan Work> python -u "c:\Users\ASUS\Desktop\Geeksgyan Work\test.py"
Enter Radius : 5
Traceback (most recent call last):
  File "c:\Users\ASUS\Desktop\Geeksgyan Work\test.py", line 3, in <module>
    area = 3.14 * radius * radius
TypeError : can't multiply sequence by non-int of type 'float'

You can see that the error occurs in our program. Now we will see the second case of the error.

Case 2:

Suppose we are writing a program in which we want the output as given below.

[ 1 , 2 , 3 , 4 , 5 , 1 , 2 , 3 , 4 , 5 ]

( ‘a’ , ‘b’ , ‘c’ , ‘a’ , ‘b’ , ‘c’ )

First, we have written our code with preferred input as shown in the example below.

list1 = [ 1, 2, 3, 4, 5 ]
tup1 = ( 'a' , 'b' , 'c' )

list1 = list1 * 2.0
tup1 = tup1 * 2.0

print ( list1 )
print ( tup1 )

When we try to run this code in our terminal then we will encounter the error as shown below.

Output:

PS C:\Users\ASUS\Desktop\Geeksgyan Work> python -u "c:\Users\ASUS\Desktop\Geeksgyan Work\test.py"
Traceback ( most recent call last ) :
  File "c:\Users\ASUS\Desktop\Geeksgyan Work\test.py", line 5, in <module>
    list1 = list1 * 2.0
TypeError: can't multiply sequence by non-int of type 'float'

From these cases, we can understand that this error mostly occurs when we try to perform operations between those datatypes which are unsupported in python.

As we can see in case 1, we were trying to perform an operation ‘multiplication’ between float datatype and string datatype. Python does not support this operation between these datatypes so it raises that error.

The same thing happening in Case 2, we are trying to perform an operation between a list and a float datatype. And in the terminal, we got an error because python does not support this operation.

To solve this error, we have to check whether we are trying to perform an operation between any two datatypes which is unsupported in python.

Let’s see the updated solution of previous cases.

Solutions for Error

Case 1:

radius = int ( input ( " Enter Radius : " ) )

area = 3.14 * radius * radius
print ( f " Area is {area} " )

Output:

PS C:\Users\ASUS\Desktop\Geeksgyan Work> python -u "c:\Users\ASUS\Desktop\Geeksgyan Work\test.py"
Enter Radius: 5
Area is 78.5

And we got the desired solution.

While we are taking inputs from the user, python default takes input as a string, now we convert it into integer so that we can perform operation ‘multiplication’. And by this way, we can solve the error.

Case 2:

In this case, we are trying to multiply the list and tuple with floating point value. And python is not supporting this so it shows the error, to eliminate this error we have to alter our code.

list1 = [ 1 , 2 , 3 , 4 , 5 ]
tup1 = ( 'a' , 'b' , 'c' )

list1 = list1 * 2
tup1 = tup1 * 2

print ( list1 )
print ( tup1 )

Output:

PS C:\Users\ASUS\Desktop\Geeksgyan Work> python -u "c:\Users\ASUS\Desktop\Geeksgyan Work\test.py"
[ 1 , 2 , 3 , 4 , 5 , 1 , 2 , 3 , 4 , 5 ]
( 'a' , 'b' , 'c' , 'a' , 'b' , 'c' )

After Modifying line 3 and 4, we can get our desired output.

In line 3 and 4, we are multiplying the list with integer value, so the operation is performed successfully, we are able to get the desired output from the code.

Conclusion

In python, we may encounter so many errors which can take much longer to find and solve that error, sometimes the error can be logical some times it can be a syntax error. We have to observe carefully to find any type of error, but finding logical errors can take much time. In this article, we have talked about the error called can’t multiply sequence by non-int of type ‘float’.

This error occurs when we are trying to perform any operation between two datatypes in which one of them is Float. That Operation will not be supported by Python.

Whenever we encounter these types of error, first we have to check whether we are trying to perform the operation between unsupported datatypes in python. When we correct this then our code will be executed successfully.

The post Solve TypeError: can’t multiply sequence by non-int of type ‘float’ in Python appeared first on The Crazy Programmer.



from The Crazy Programmer https://ift.tt/AalWLKQ

In python, there are many types of errors as once the code has many types of problems in which this error will come. Errors will always define which type of problem has occurred in the solution.

In this article we will go through the Typeerror: unhashable type ‘list’ and what causes this error and how to get the solution for it from some of the programs.

Let’s talk about hashable as it is a feature of python objects and this tells about hash value as if any object has hash value then we can use it as a key value in the dictionary otherwise, we can use it for addition as a set element.

Example:

{Key1:Value1, Key2:Value2, Key3:Value3}

{setObject1, setObject2, setObject3}

Now there is a problem to know which object is hashable and which object is not. The objects in python which are immutable and have a hash value are called hashable and which are mutable and don’t have a hash value are called unhashable. Immutable are those which cannot be modified as a number, string, and tuple ex: num = 63, answer = ’bye’.

Mutable are those which can be modified as a list, dictionary ex: set = [2, 3, 4, 5] {1:5,2:10,3:15}

So unhashable doesn’t have a hash value so we cannot use it as a key in the dictionary or cannot add an element in the set.

Reasons for Error

Case 1:

Suppose we are taking a list of numbers and now trying to find out the hash value of the list.

numbers={23,45,[34,27],35}
print(numbers)

Now we are trying to find hash value for the set and when are printing the value the error occurs as the hash value is not coming so we cannot use it as a key in the dictionary in the set.

Traceback (most recent call last):
  File "c:\Users\91930\Documents\work\article2.py", line 1, in <module>
    numbers={23,45,[34,27],35}
TypeError: unhashable type: 'list'

So to avoid this error by removing the mutable object or replacing it with some immutable object and your code will run properly. The set or dictionary will use a hash statement for the storage of elements. A particular hashcode is being given to the set. The list is mutable so we can do implementation on the list at any time in the code and it will give unhashable value.

Case 2:

Suppose we are taking the employees and finding their marks of training to decide the promotion and we are taking the information in the dictionary.

employee = [
        { "name": "Tom", "marks": [44, 62, 95] },
        { "name": "Peter", "marks": [87, 98, 53] },
        { "name": "Gwen", "marks": [72, 54, 41] }
]
best_employee = {}
for e in employee:
                 avg_marks = sum(e["marks"]) / len(e["marks"])
                 if avg_marks > 45:
                         best_employee[e["marks"]] =e["name"]
                         
print(best_employee)

Now we are running the program and it is returning back an error that the list cannot be hashable and we cannot get the hash value.

Traceback (most recent call last):
  File "<string>", line 12, in <module>
TypeError: unhashable type: 'list'

Solutions for Error

Case 1:

To solve this error we will convert the list into a hashable object as hashable objects are immutable and we cannot modify it later. So we will convert the list into a tuple then we can use it as a key for a particular set. Then we will get the hash value of the list and the error will be solved.

Here the output is the list and we got the solution to remove the error and the revised code.

numbers={23,45,tuple([34,27]),35}
print(numbers)

Output:

{(34, 27), 35, 45, 23}

Case 2:

To solve the error we will see what comes in the error.

best_employee[e["marks"]] =e["name"]

The error has been encountered in our code as we are putting a list as a key in dict. When we are iterating this line of code then we are creating a dictionary that has a key and value as like:

{[44, 62, 95]: "Tom"}

This will be an invalid dictionary as the dictionary is telling us to know that there is a key and has its value which fails to work. To solve this problem we will use the employee name as key and marks will be the values.

best_employee[e["name"]] =e["marks"]

We have provided the marks as the values without putting them as keys.

The revised code is as:

employee = [
    { "name": "Tom", "marks": [44, 62, 95] },
    { "name": "Peter", "marks": [87, 98, 53] },
    { "name": "Gwen", "marks": [72, 54, 41] }
]
best_employee = {}
for e in employee:
         avg_marks = sum(e["marks"]) / len(e["marks"])
         if avg_marks > 45:
                 best_employee[e["name"]] =e["marks"]
                 
print(best_employee)

Output:

{'Tom': [44, 62, 95], 'Peter': [87, 98, 53], 'Gwen': [72, 54, 41]}

Our code is now working properly without having any error as the employees name will be in the dictionary whose average marks above 45.

Conclusion

The TypeError: unhashable type ’list’ error has occurred when we are trying to give the list as a key in the dictionary and as the list is mutable so we can modify it and it will provide unhashashble value and the error occurs. When we want a hash value then the objects should be immutable then we will get hashable objects. Hashing we want to know about it as the method of converting the data to a similar size of integer which will only give the perfect value and we can only hash the elements which are hashable.

To solve this error we are assigning a hashable object instead of the unhashable object such as a tuple for the list so that the list can give the output. Another solution for adding a list in a dictionary is by storing it as a value. We will be meeting many problems later if we are passing values as a list so better to pass the values as strings, tuples, etc. string, tuples are immutable and we cannot modify them later. For a better version for passing a string without an error, we will pass it as a tuple and then we are seeing the hash value for it and a better conversion begins with it.

The post Solve Typeerror: unhashable type ‘list’ in Python appeared first on The Crazy Programmer.



from The Crazy Programmer https://ift.tt/WCtavsr

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget