<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Ramakrushna Mohapatra</title>
    <description>The latest articles on Forem by Ramakrushna Mohapatra (@ramakm).</description>
    <link>https://forem.com/ramakm</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F455622%2F1aeed711-f4a4-4f41-8619-1dfdb644a374.jpg</url>
      <title>Forem: Ramakrushna Mohapatra</title>
      <link>https://forem.com/ramakm</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ramakm"/>
    <language>en</language>
    <item>
      <title>Chatbot: Building From Scratch</title>
      <dc:creator>Ramakrushna Mohapatra</dc:creator>
      <pubDate>Tue, 29 Aug 2023 12:11:41 +0000</pubDate>
      <link>https://forem.com/ramakm/chatbot-building-from-scratch-32j5</link>
      <guid>https://forem.com/ramakm/chatbot-building-from-scratch-32j5</guid>
      <description>&lt;p&gt;Please read from start and end. If you will follow what I have mentioned here, you will able to build a chatbot without anyone's help. Believe me its gonna be a fun ride blog for you.&lt;br&gt;
Be patience!&lt;/p&gt;
&lt;h1&gt;
  
  
  &lt;strong&gt;What is a Chatbot?&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;Perhaps you have heard this term and wondered: what is this chatbot, what is it used for, do I really need one, how can I create one?&lt;br&gt;
A chatbot is a computer program designed to simulate human conversation, offering automated responses and assistance. It uses natural language processing to understand and generate text-based interactions. Chatbots are used for various tasks, from customer support to information retrieval, providing instant communication and problem-solving in diverse applications.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XCO_8GBQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p4tgtfeuwrberj1zmxxu.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XCO_8GBQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p4tgtfeuwrberj1zmxxu.jpg" alt="Image description" width="800" height="507"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Preliminaries:&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Python&lt;/li&gt;
&lt;li&gt;Flask Framework&lt;/li&gt;
&lt;li&gt;ML &amp;amp; its Algorithms&lt;/li&gt;
&lt;li&gt;HTML &amp;amp; CSS Basics&lt;/li&gt;
&lt;li&gt;Json Basics&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;
  
  
  &lt;strong&gt;Where it is used?&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;Chatbots find versatile applications across industries, making it impractical to detail all potential uses. However, they are commonly employed in: customer service desks, facilitating transactions, offering customer support, managing bookings, and ensuring round-the-clock real-time interactions with clients. These applications showcase the wide-reaching utility of chatbots in enhancing efficiency and user experiences.&lt;/p&gt;
&lt;h1&gt;
  
  
  &lt;strong&gt;Is it necessary to create one?&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;Certainly, determining the viability of such a venture involves a personalized assessment of costs and benefits. In today's technological landscape, numerous enterprises are progressively adopting chatbots for essential everyday operations. Prominent instances include Google Assistant, Apple Siri, Samsung Bixby, and Amazon Alexa.&lt;br&gt;
Within this article, we'll delve into crafting a chatbot using Python, leveraging TensorFlow for model training, and employing Natural Language Processing (nltk) to enhance the machine's comprehension of user inquiries.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Types of chatbots:&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Rule-Based approach&lt;/strong&gt; - Here the bot is trained based on some set rules. It is from these rules that the bot can process simple queries but can fail to process complex ones.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Self-Learning approach&lt;/strong&gt; - Here the bot uses some machine learning algorithms and techniques to chat. It is further subcategorized into two:&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Retrieval-Based models&lt;/strong&gt; - In this model, the bot retrieves the best response from a list depending on the user input.
Generative models - This model comes up with an answer rather than searching from a given list. These are the Intelligent Bots.&lt;/li&gt;
&lt;/ol&gt;
&lt;h1&gt;
  
  
  &lt;strong&gt;Terminology To Interact With&lt;/strong&gt;
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Natural Language Processing(nltk):&lt;/strong&gt; It is a powerful Python library widely used for working with human language data, particularly in the field of natural language processing (NLP). NLTK provides tools, resources, and algorithms for various tasks in NLP, such as tokenization, stemming, part-of-speech tagging, parsing, and more.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lemmatization:&lt;/strong&gt; This is the process of grouping together the different inflected forms of a word so they can be analyzed as a single item and is a variation of stemming. For example "feet" and "foot" are both recognized as "foot".&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stemming:&lt;/strong&gt; This is the process of reducing inflected words to their word stem, base, or root form. For example, if we were to stem the word "eat", "eating", "eats", the result would be the single word "eat".&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tokenization:&lt;/strong&gt; Tokenization in NLP refers to the process of breaking down a text or a sequence of characters into individual units, typically words or sub-words, known as tokens. These tokens are the basic building blocks for further analysis in natural language processing tasks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bag of Words:&lt;/strong&gt; This is an NLP technique of text modeling for representing text data for machine learning algorithms. It is a way of extracting features from the text for use in machine learning algorithms.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Enough of basic theory now, let's jump into work.&lt;/p&gt;
&lt;h1&gt;
  
  
  &lt;strong&gt;Let's Jump To Programming&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;Files you need are available in my GitHub repo. To clone or download, go to this link:&lt;br&gt;
&lt;a href="https://github.com/Ramakm/AI-Chatbot"&gt;AI Chatbot: GitHub Link&lt;/a&gt;&lt;br&gt;
Initially, it's important to confirm the availability of necessary libraries and modules. To do so, utilize the given command to install TensorFlow, nltk, and flask.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$pip install tensorflow
$pip install nltk
$pip install flask
$pip install tensorflow-gpu
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will have a &lt;code&gt;intents.json&lt;/code&gt; which will contain the tag, pattern, response and context. Its a simple file where all your questions and answers will be there to train the model. The file you can see here in this link intents.json.&lt;br&gt;
First we will train our model by creating a new .py file named as:&lt;br&gt;
&lt;code&gt;train.py&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Import the necesseary libraries
import random
from tensorflow.keras.optimizers import SGD
from keras.layers import Dense, Dropout
from keras.models import load_model
from keras.models import Sequential
import numpy as np
import pickle
import json
import nltk
from nltk.stem import WordNetLemmatizer
Let's initializes a lemmatizer using the WordNetLemmatizer class. It then downloads linguistic resources: the Open Multilingual Wordnet, essential for multilingual NLP, and word-related datasets (punkt and wordnet) for text processing tasks using the Natural Language Toolkit (NLTK) library in Python.
lemmatizer = WordNetLemmatizer()
nltk.download('omw-1.4')
nltk.download("punkt")
nltk.download("wordnet")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We now need to initialize some files and load our training data. Note that we are going to be ignoring "?" and "!". If you have some other symbols or letters that you want the model to ignore you can add them at the ignore_words array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# initialize the files
words = []
classes = []
documents = []
ignore_words = ["?", "!"]
data_file = open("intents.json").read()
intents = json.loads(data_file)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;NOTE! If you are getting while running due to the path in data_file while loading the intents.json file. Please try to do like this. Rememmber X,Y,Z are random letter. That should be the exact path where your intents.json file stored&lt;/p&gt;

&lt;p&gt;&lt;code&gt;F:\\X\\Y\\Z\\intents.json&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then we tokenize our words. It's like dissecting a sentence into its fundamental components. For instance, the sentence "I love pizza" would be tokenized into three tokens: "I," "love," and "pizza."&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# words
for intent in intents["intents"]:
    for pattern in intent["patterns"]:

        # take each word and tokenize it
        w = nltk.word_tokenize(pattern)
        words.extend(w)
        # adding documents
        documents.append((w, intent["tag"]))

        # adding classes to our class list
        if intent["tag"] not in classes:
            classes.append(intent["tag"])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we shall lemmatize the words and dump them in a pickle file&lt;br&gt;
After tokenization, the words are further processed through lemmatization. Lemmatization involves reducing words to their base or root form. For example, "running" becomes "run," "better" becomes "good." These lemmatized words are then saved into a pickle file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# lemmatizer
words = [lemmatizer.lemmatize(w.lower()) for w in words if w not in ignore_words]
words = sorted(list(set(words)))

classes = sorted(list(set(classes)))

print(len(documents), "documents")

print(len(classes), "classes", classes)

print(len(words), "unique lemmatized words", words)

pickle.dump(words, open("words.pkl", "wb"))
pickle.dump(classes, open("classes.pkl", "wb"))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After preparing training data for a chatbot. We tokenize, lemmatize, and create a "bag of words" representation for each text pattern.&lt;/p&gt;

&lt;p&gt;Now let's generate output labels for each class. Data is shuffled and organized into NumPy arrays. This structured data is crucial for training the chatbot's model to associate patterns with their respective intents. We initialize the model training&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;training = []
output_empty = [0] * len(classes)
for doc in documents:
    # initializing bag of words
    bag = []
    # list of tokenized words for the pattern
    pattern_words = doc[0]
    # lemmatize each word - create base word, in attempt to represent related words
    pattern_words = [lemmatizer.lemmatize(word.lower()) for word in pattern_words]
    # create our bag of words array with 1, if word match found in current pattern
    for w in words:
        bag.append(1) if w in pattern_words else bag.append(0)

    # output is a '0' for each tag and '1' for current tag (for each pattern)
    output_row = list(output_empty)
    output_row[classes.index(doc[1])] = 1

    training.append([bag, output_row])

# shuffle our features and turn into np.array
random.shuffle(training)

# Separate bag-of-words representations and output labels
train_x = [item[0] for item in training]
train_y = [item[1] for item in training]

# Convert to NumPy arrays
train_x = np.array(train_x)
train_y = np.array(train_y)
print("Training data created")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We are constructing a three-layer output model. The initial layer consists of 128 neurons, followed by a second layer with 64 neurons. The third layer is tailored to match the count of intents, using a number of neurons equal to the intents to predict outcomes via softmax activation. Our choice of the Rectified Linear Unit (ReLU) activation function aims to ensure simpler training and achieve commendable performance results.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Create model - 3 layers. First layer 128 neurons, second layer 64 neurons and 3rd output layer contains number of neurons
# equal to number of intents to predict output intent with softmax
model = Sequential()
model.add(Dense(128, input_shape=(len(train_x[0]),), activation="relu"))
model.add(Dropout(0.5))
model.add(Dense(64, activation="relu"))
model.add(Dropout(0.5))
model.add(Dense(len(train_y[0]), activation="softmax"))
model.summary()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, we compile the model. Stochastic gradient descent with Nesterov accelerated gradient gives good results for this model. I won't go into details about Stochastic gradient descent as this is a vastly complicated topic on its own.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sgd = SGD(learning_rate=0.01, momentum=0.9, nesterov=True)
model.compile(loss="categorical_crossentropy", optimizer=sgd, metrics=["accuracy"])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the model is being trained and saved. Training involves using the input data (train_x) and output labels (train_y) for 200 epochs with batch size 5. The resulting model, along with training history, is saved as "chatbot_model.h5". This completes the model creation process.&lt;br&gt;
we can train our model and save it for fast access from the Flask REST API without the need of retraining. code for this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# fitting and saving the model
hist = model.fit(np.array(train_x), np.array(train_y), epochs=200, batch_size=5, verbose=1)
model.save("chatbot_model.h5", hist)
print("model created")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One new file will be added to your folder once this &lt;code&gt;train.py&lt;/code&gt; will get run successfully. The file name would be &lt;strong&gt;chatbot_model.h5&lt;/strong&gt;.&lt;br&gt;
Please remember before running this program, if you have clone my repo from GitHub or downloaded and put it in any idle, try to remove the chatbot_model.h5 as it will get generated by running the &lt;code&gt;train.py&lt;/code&gt; file.&lt;br&gt;
So final train.py should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# libraries
import random
from tensorflow.keras.optimizers import SGD
from keras.layers import Dense, Dropout
from keras.models import load_model
from keras.models import Sequential
import numpy as np
import pickle
import json
import nltk
from nltk.stem import WordNetLemmatizer
lemmatizer = WordNetLemmatizer()
nltk.download('omw-1.4')
nltk.download("punkt")
nltk.download("wordnet")

# init file
words = []
classes = []
documents = []
ignore_words = ["?", "!"]
data_file = open("F:\\Data Science Course - IIITB\\NLP\\Chatbot\\AI Chatbot\\An-AI-Chatbot-in-Python-and-Flask-main\\intents.json").read()
intents = json.loads(data_file)

# words
for intent in intents["intents"]:
    for pattern in intent["patterns"]:

        # take each word and tokenize it
        w = nltk.word_tokenize(pattern)
        words.extend(w)
        # adding documents
        documents.append((w, intent["tag"]))

        # adding classes to our class list
        if intent["tag"] not in classes:
            classes.append(intent["tag"])

# lemmatizer
words = [lemmatizer.lemmatize(w.lower()) for w in words if w not in ignore_words]
words = sorted(list(set(words)))

classes = sorted(list(set(classes)))

print(len(documents), "documents")

print(len(classes), "classes", classes)

print(len(words), "unique lemmatized words", words)

pickle.dump(words, open("words.pkl", "wb"))
pickle.dump(classes, open("classes.pkl", "wb"))

# initializing training data
training = []
output_empty = [0] * len(classes)
for doc in documents:
    # initializing bag of words
    bag = []
    # list of tokenized words for the pattern
    pattern_words = doc[0]
    # lemmatize each word - create base word, in attempt to represent related words
    pattern_words = [lemmatizer.lemmatize(word.lower()) for word in pattern_words]
    # create our bag of words array with 1, if word match found in current pattern
    for w in words:
        bag.append(1) if w in pattern_words else bag.append(0)

    # output is a '0' for each tag and '1' for current tag (for each pattern)
    output_row = list(output_empty)
    output_row[classes.index(doc[1])] = 1

    training.append([bag, output_row])

# shuffle our features and turn into np.array
random.shuffle(training)

# Separate bag-of-words representations and output labels
train_x = [item[0] for item in training]
train_y = [item[1] for item in training]

# Convert to NumPy arrays
train_x = np.array(train_x)
train_y = np.array(train_y)
print("Training data created")

# Create model - 3 layers. First layer 128 neurons, second layer 64 neurons and 3rd output layer contains number of neurons
# equal to number of intents to predict output intent with softmax
model = Sequential()
model.add(Dense(128, input_shape=(len(train_x[0]),), activation="relu"))
model.add(Dropout(0.5))
model.add(Dense(64, activation="relu"))
model.add(Dropout(0.5))
model.add(Dense(len(train_y[0]), activation="softmax"))
model.summary()

sgd = SGD(learning_rate=0.01, momentum=0.9, nesterov=True)
model.compile(loss="categorical_crossentropy", optimizer=sgd, metrics=["accuracy"])

# fitting and saving the model
hist = model.fit(np.array(train_x), np.array(train_y), epochs=200, batch_size=5, verbose=1)
model.save("chatbot_model.h5", hist)
print("model created")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the train.py to create the model.&lt;br&gt;
Now that we are done with training let's create the Flask interface to initialize the chat functionalities. Create a .py file named as &lt;code&gt;app.py&lt;/code&gt;&lt;br&gt;
We load the required libraries and initialize the Flask app.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# import the necessesary libraries
import random
import numpy as np
import pickle
import json
from flask import Flask, render_template, request
from flask_ngrok import run_with_ngrok
import nltk
from keras.models import load_model
from nltk.stem import WordNetLemmatizer
lemmatizer = WordNetLemmatizer()
# chat initialization
model = load_model("chatbot_model.h5")
# intents = json.loads(open("intents.json").read())
data_file = open("intents.json").read()
words = pickle.load(open("words.pkl", "rb"))
classes = pickle.load(open("classes.pkl", "rb"))

app = Flask(__name__)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We're initializing the chat process. The saved model is loaded, and intent data is read from a &lt;code&gt;intents.json&lt;/code&gt; file. Word and class information is loaded from pickle files. This setup is for the Flask-based web application using Python, facilitating communication with the chatbot through user interactions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE!&lt;/strong&gt; If you are getting while running due to the path in data_file while loading the intents.json file. Please try to do like this. Rememmber X,Y,Z are random letter. That should be the exact path where your intents.json file stored&lt;/p&gt;

&lt;p&gt;&lt;code&gt;F:\\X\\Y\\Z\\intents.json&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@app.route("/")
def home():
    return render_template("index.html")

@app.route("/get", methods=["POST"])
def chatbot_response():
    msg = request.form["msg"]

    # Load and process the intents JSON file
    data_file = open("intents.json").read()
    intents = json.loads(data_file)

    # Rest of your existing code
    if msg.startswith('my name is'):
        name = msg[11:]
        ints = predict_class(msg, model)
        res1 = getResponse(ints, intents)
        res = res1.replace("{n}", name)
    elif msg.startswith('hi my name is'):
        name = msg[14:]
        ints = predict_class(msg, model)
        res1 = getResponse(ints, intents)
        res = res1.replace("{n}", name)
    else:
        ints = predict_class(msg, model)
        res = getResponse(ints, intents)
    return res
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code defines a Flask app with routes for rendering an HTML interface and handling chatbot responses. User messages are processed, and the intents.json is loaded. Predicted classes trigger relevant responses, which can include personalized greetings using extracted names. The app facilitates user interactions and chatbot engagement on a web interface.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# chat functionalities
def clean_up_sentence(sentence):
    sentence_words = nltk.word_tokenize(sentence)
    sentence_words = [lemmatizer.lemmatize(word.lower()) for word in sentence_words]
    return sentence_words

# return bag of words array: 0 or 1 for each word in the bag that exists in the sentence
def bow(sentence, words, show_details=True):
    # tokenize the pattern
    sentence_words = clean_up_sentence(sentence)
    # bag of words - matrix of N words, vocabulary matrix
    bag = [0] * len(words)
    for s in sentence_words:
        for i, w in enumerate(words):
            if w == s:
                # assign 1 if current word is in the vocabulary position
                bag[i] = 1
                if show_details:
                    print("found in bag: %s" % w)
    return np.array(bag)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above function will call the following functions which clean up sentences and return a bag of words based on the user input.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def predict_class(sentence, model):
    # filter out predictions below a threshold
    p = bow(sentence, words, show_details=False)
    res = model.predict(np.array([p]))[0]
    ERROR_THRESHOLD = 0.25
    results = [[i, r] for i, r in enumerate(res) if r &amp;gt; ERROR_THRESHOLD]
    # sort by strength of probability
    results.sort(key=lambda x: x[1], reverse=True)
    return_list = []
    for r in results:
        return_list.append({"intent": classes[r[0]], "probability": str(r[1])})
    return return_list

def getResponse(ints, intents_json):
    tag = ints[0]["intent"]
    list_of_intents = intents_json["intents"]
    for i in list_of_intents:
        if i["tag"] == tag:
            result = random.choice(i["responses"])
            break
    return result
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;"predict_class"&lt;/strong&gt; function analyzes input text using a trained model, filtering predictions based on a threshold. It sorts and returns intents with probabilities exceeding the threshold. &lt;strong&gt;"getResponse"&lt;/strong&gt; retrieves a response based on the highest probability intent, selecting from predefined responses in the intents JSON. These functions enable accurate classification and appropriate responses in the chatbot application.&lt;br&gt;
Final &lt;code&gt;app.py&lt;/code&gt; file should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# libraries
import random
import numpy as np
import pickle
import json
from flask import Flask, render_template, request
from flask_ngrok import run_with_ngrok
import nltk
from keras.models import load_model
from nltk.stem import WordNetLemmatizer
lemmatizer = WordNetLemmatizer()

# chat initialization
model = load_model("chatbot_model.h5")
# intents = json.loads(open("intents.json").read())
data_file = open("F:\\Data Science Course - IIITB\\NLP\\Chatbot\\AI Chatbot\\An-AI-Chatbot-in-Python-and-Flask-main\\intents.json").read()
words = pickle.load(open("words.pkl", "rb"))
classes = pickle.load(open("classes.pkl", "rb"))

app = Flask(__name__)
# run_with_ngrok(app) 

@app.route("/")
def home():
    return render_template("index.html")

@app.route("/get", methods=["POST"])
def chatbot_response():
    msg = request.form["msg"]

    # Load and process the intents JSON file
    data_file = open("F:\\Data Science Course - IIITB\\NLP\\Chatbot\\AI Chatbot\\An-AI-Chatbot-in-Python-and-Flask-main\\intents.json").read()
    intents = json.loads(data_file)

    # Rest of your existing code
    if msg.startswith('my name is'):
        name = msg[11:]
        ints = predict_class(msg, model)
        res1 = getResponse(ints, intents)
        res = res1.replace("{n}", name)
    elif msg.startswith('hi my name is'):
        name = msg[14:]
        ints = predict_class(msg, model)
        res1 = getResponse(ints, intents)
        res = res1.replace("{n}", name)
    else:
        ints = predict_class(msg, model)
        res = getResponse(ints, intents)
    return res

# chat functionalities
def clean_up_sentence(sentence):
    sentence_words = nltk.word_tokenize(sentence)
    sentence_words = [lemmatizer.lemmatize(word.lower()) for word in sentence_words]
    return sentence_words

# return bag of words array: 0 or 1 for each word in the bag that exists in the sentence
def bow(sentence, words, show_details=True):
    # tokenize the pattern
    sentence_words = clean_up_sentence(sentence)
    # bag of words - matrix of N words, vocabulary matrix
    bag = [0] * len(words)
    for s in sentence_words:
        for i, w in enumerate(words):
            if w == s:
                # assign 1 if current word is in the vocabulary position
                bag[i] = 1
                if show_details:
                    print("found in bag: %s" % w)
    return np.array(bag)

def predict_class(sentence, model):
    # filter out predictions below a threshold
    p = bow(sentence, words, show_details=False)
    res = model.predict(np.array([p]))[0]
    ERROR_THRESHOLD = 0.25
    results = [[i, r] for i, r in enumerate(res) if r &amp;gt; ERROR_THRESHOLD]
    # sort by strength of probability
    results.sort(key=lambda x: x[1], reverse=True)
    return_list = []
    for r in results:
        return_list.append({"intent": classes[r[0]], "probability": str(r[1])})
    return return_list

def getResponse(ints, intents_json):
    tag = ints[0]["intent"]
    list_of_intents = intents_json["intents"]
    for i in list_of_intents:
        if i["tag"] == tag:
            result = random.choice(i["responses"])
            break
    return result

if __name__ == "__main__":
    app.run()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have lastly index.html and style.css file. I don't think we need to go into details about these files as there are basic HTML and CSS codes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;index.html
&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;

&amp;lt;head&amp;gt;
    &amp;lt;link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css')}}" /&amp;gt;
    &amp;lt;!-- &amp;lt;link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css.css')}}" /&amp;gt; --&amp;gt;
    &amp;lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
    &amp;lt;div class="row"&amp;gt;
        &amp;lt;div class="col-md-10 mr-auto ml-auto"&amp;gt;
            &amp;lt;h1&amp;gt;Ramakrushna Mohapatra-ChatBot&amp;lt;/h1&amp;gt;
            &amp;lt;form&amp;gt;
                &amp;lt;div id="chatbox"&amp;gt;
                    &amp;lt;div class="col-md-8 ml-auto mr-auto text-center"&amp;gt;
                        &amp;lt;p class="botText"&amp;gt;&amp;lt;span&amp;gt;Hi! I'm Your bot.&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;
                    &amp;lt;/div&amp;gt;
                &amp;lt;/div&amp;gt;
                &amp;lt;div id="userInput" class="row"&amp;gt;
                    &amp;lt;div class="col-md-10"&amp;gt;
                        &amp;lt;input id="text" type="text" name="msg" placeholder="Message" class="form-control"&amp;gt;
                        &amp;lt;button type="submit" id="send" class="btn btn-warning"&amp;gt;Send&amp;lt;/button&amp;gt;
                    &amp;lt;/div&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/form&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;

    &amp;lt;script&amp;gt;
        $(document).ready(function() {
            $("form").on("submit", function(event) {
                var rawText = $("#text").val();
                var userHtml = '&amp;lt;p class="userText"&amp;gt;&amp;lt;span&amp;gt;' + rawText + "&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;";
                $("#text").val("");
                $("#chatbox").append(userHtml);
                document.getElementById("userInput").scrollIntoView({
                    block: "start",
                    behavior: "smooth",
                });
                $.ajax({
                    data: {
                        msg: rawText,
                    },
                    type: "POST",
                    url: "/get",
                }).done(function(data) {
                    var botHtml = '&amp;lt;p class="botText"&amp;gt;&amp;lt;span&amp;gt;' + data + "&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;";
                    $("#chatbox").append($.parseHTML(botHtml));
                    document.getElementById("userInput").scrollIntoView({
                        block: "start",
                        behavior: "smooth",
                    });
                });
                event.preventDefault();
            });
        });
    &amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;style.css&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;body {
    font-family: Garamond;
}

h1 {
    color: black;
    margin-bottom: 0;
    margin-top: 0;
    text-align: center;
    font-size: 40px;
}

h3 {
    color: black;
    font-size: 20px;
    margin-top: 3px;
    text-align: center;
}
.row {
    display: flex;
    flex-wrap: wrap;
    margin-right: -15px;
    margin-left: -15px;
}

.ml-auto{
    margin-left:auto !important;
}
.mr-auto{
    margin-right:auto !important;
}

.col-md-10,.col-md-8,.col-md-4{
    position: relative;
    width: 100%;
    min-height: 1px;
    padding-right: 15px;
    padding-left: 15px;
}
.col-md-8{flex:0 0 66.666667%;max-width:66.666667%}
.col-md-4{flex:0 0 33.333333%;max-width:33.333333%}
.col-md-10{flex:0 0 83.333333%;max-width:83.333333%}

.form-control {
    background: no-repeat bottom,50% calc(100% - 1px);
    background-image: none, none;
    background-size: auto, auto;
    background-size: 0 100%,100% 100%;
    border: 0;
    height: 36px;
    transition: background 0s ease-out;
    padding-left: 0;
    padding-right: 0;
    border-radius: 0;
    font-size: 14px;
}
.form-control {
    display: block;
    width: 100%;
    padding: .4375rem 0;
    padding-right: 0px;
    padding-left: 0px;
    font-size: 1rem;
    line-height: 1.5;
    color: #495057;
    border:none;
    background-color: transparent;
    background-clip: padding-box;
    border-bottom: 1px solid #d2d2d2;
    box-shadow: none;
    transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out;
}
.btn {
    float: left;
    text-align: center;
    white-space: nowrap;
    vertical-align: middle;
    user-select: none;
    border: 1px solid transparent;
    padding: .46875rem 1rem;
    font-size: 1rem;
    line-height: 1.5;
    border-radius: .25rem;
    transition: color .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out;
}
.btn-warning {
    color: #fff;
    background-color: #f08f00;
    border-color: #c27400;
}
.btn.btn-warning:active, .btn.btn-warning:focus, .btn.btn-warning:hover {
    box-shadow: 0 14px 26px -12px rgba(255,152,0,.42),0 4px 23px 0 rgba(0,0,0,.12),0 8px 10px -5px rgba(255,152,0,.2);
}

button, input, optgroup, select, textarea {
    margin: 0;
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
    overflow:visible;
}
#chatbox {
    background-color: cyan;
    margin-left: auto;
    margin-right: auto;
    width: 80%;
    min-height: 70px;
    margin-top: 60px;
}

#userInput {
    margin-left: auto;
    margin-right: auto;
    width: 40%;
    margin-top: 60px;
}

#textInput {
    width: 87%;
    border: none;
    border-bottom: 3px solid #009688;
    font-family: monospace;
    font-size: 17px;
}

#buttonInput {
    padding: 3px;
    font-family: monospace;
    font-size: 17px;
}

.userText {
    color: white;
    font-family: monospace;
    font-size: 17px;
    text-align: right !important;
    line-height: 30px;
    margin: 5px;
}

.userText span {
    background-color: #009688;
    padding: 10px;
    border-radius: 2px;
}

.botText {
    color: white;
    font-family: monospace;
    font-size: 17px;
    text-align: left;
    line-height: 30px;
    margin: 5px;
}

.botText span {
    background-color: #ef5350;
    padding: 10px;
    border-radius: 2px;
}

#tidbit {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 300px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  &lt;strong&gt;Executions Process&lt;/strong&gt;
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Firstly, Just delete the existing chatbot_model.h5 file from the folder.&lt;/li&gt;
&lt;li&gt;Then, run the train.py file to train the model. This will generate a file named &lt;code&gt;chatbot_model.h5&lt;/code&gt;. You will face error becauz if you haven't changed the path of the &lt;code&gt;intents.json&lt;/code&gt; file path in datafile variable.&lt;/li&gt;
&lt;li&gt;This is the model which will be used by the Flask REST API to easily give feedback without the need to retrain.&lt;/li&gt;
&lt;li&gt;After running &lt;code&gt;train.py&lt;/code&gt;, next run the &lt;code&gt;app.py&lt;/code&gt; to initialize and start the bot.&lt;/li&gt;
&lt;li&gt;To add more terms and vocabulary to the bot, modify the &lt;code&gt;intents.json&lt;/code&gt; file and add your personalized words and retrain the model again.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Accessing the Chatbot:&lt;/strong&gt; After running the Flask app (app.py), you can access the chatbot by navigating to &lt;code&gt;http://127.0.0.1:5000/&lt;/code&gt; in your web browser. If you're using ngrok, you'll access the chatbot through the Ngrok-generated URL.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2aYecOao--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dlkm0tm2swdwfi2vzjty.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2aYecOao--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dlkm0tm2swdwfi2vzjty.gif" alt="Image description" width="" height=""&gt;&lt;/a&gt;&lt;br&gt;
There you are! Your chatbot is ready. Your webpage gonna look something like this:&lt;br&gt;
For the full code with all the files visit my GitHub repo. Don't forget to Star if you find it helpful.&lt;br&gt;
Follow me on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Twitter:&lt;/strong&gt; &lt;a href="https://twitter.com/codewith_ram"&gt;@codewith_ram&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a href="https://github.com/ramakm"&gt;@Ramakm&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Kaggle:&lt;/strong&gt; &lt;a href="https://kaggle.com/ramakrushnamohapatra"&gt;@ramakrushnamohapatra&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;LinkedIN:&lt;/strong&gt; &lt;a href="https://www.linkedin.com/in/ramakrushnamohapatra"&gt;@ramakrushna&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If this helped you in any part of your professional life. Give it a like and comment.&lt;/p&gt;

</description>
      <category>chatgpt</category>
      <category>chatbot</category>
      <category>datascience</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>Open Source: Github From Zero to Hero</title>
      <dc:creator>Ramakrushna Mohapatra</dc:creator>
      <pubDate>Wed, 07 Sep 2022 07:25:12 +0000</pubDate>
      <link>https://forem.com/ramakm/open-source-github-from-zero-to-hero-11f1</link>
      <guid>https://forem.com/ramakm/open-source-github-from-zero-to-hero-11f1</guid>
      <description>&lt;h1&gt;
  
  
  What is Git?
&lt;/h1&gt;

&lt;p&gt;git is a free opensource version control system. Most widely used version control system used by developers today. So, you might be thinking &lt;br&gt;
what is this version control???&lt;/p&gt;

&lt;p&gt;Don't worry I got you covered here as well. Version control means the management of documents, programs, large websites and other collection of information.&lt;/p&gt;

&lt;p&gt;Layman terms, if you are changing anything to your code, git will show you which day you changed what to your code.&lt;/p&gt;
&lt;h3&gt;
  
  
  Terms Frequently Used
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Directory:&lt;/strong&gt; Means Folder &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Terminal or Command Line:&lt;/strong&gt; Interface for Text Command&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CLI :&lt;/strong&gt; Command Line Interface&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;cd:&lt;/strong&gt; Change Directory&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Code Editor:&lt;/strong&gt; Writing Code like VS Code&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Repository:&lt;/strong&gt; Project/ Place where you kept your project&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Git :&lt;/strong&gt; Tool that tracks the changes of your code over time&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Github:&lt;/strong&gt; A Website where you host your all repositories&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As a programmer I would suggest you guys to go for command line interface (CLI) as you will get accustomed Git commands. You are going to use CLI so much in your developing career. So, starting it from Git command will help you a lot.&lt;/p&gt;
&lt;h1&gt;
  
  
  Frequently Used Git Commands
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Clone:&lt;/strong&gt;  Bring a repository which is hosted in a site like 
      github to your local machine&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;add:&lt;/strong&gt;   Track your file and changes in Git&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;commit:&lt;/strong&gt; Save your file in Git&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;push:&lt;/strong&gt;   Upload git commit to a remote repository, like 
      Github.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;pull:&lt;/strong&gt;   Download changes from remote repo to your local 
      machine,the opposite of push&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So what are you waiting for signup now and open a github account and explore. Once you will sign-up. page will look something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_qXge8Z_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z7h019rmvfztzd8xst72.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_qXge8Z_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z7h019rmvfztzd8xst72.jpg" alt="Image description" width="880" height="312"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Create a repository using &lt;code&gt;New&lt;/code&gt; one the left side or &lt;code&gt;+&lt;/code&gt; on the top of right side or you can create one using your local machine.&lt;/p&gt;
&lt;h2&gt;
  
  
  Using Local Machine Cretae a Repo
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Open Command line &lt;/li&gt;
&lt;li&gt;Check if git already installed or not&lt;/li&gt;
&lt;li&gt;If yes, check version using command: git --version&lt;/li&gt;
&lt;li&gt;If not, go though the below link,
&lt;a href="https://www.atlassian.com/git/tutorials/install-git"&gt;Git install Link&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Now you need a code editor. I am going to tell you in Visual Studio.&lt;/li&gt;
&lt;li&gt;Open a Folder in Visual Studio.&lt;/li&gt;
&lt;li&gt;There will a terminal in visual studio.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qPRfDLOF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/adqvx2gdnnx4a3l0ir8o.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qPRfDLOF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/adqvx2gdnnx4a3l0ir8o.jpg" alt="Image description" width="880" height="171"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now clone the repo to your local folder. Type below in VS terminal. The link I copied from Github repo.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--l3vLv4N7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7zo5ksn2y7r51f28owwi.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--l3vLv4N7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7zo5ksn2y7r51f28owwi.jpg" alt="Image description" width="880" height="296"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git clone https://github.com/Ramakm/demo-.git&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--P92Mzzcn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zpbotlihz1i6zlecqtu8.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--P92Mzzcn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zpbotlihz1i6zlecqtu8.jpg" alt="Image description" width="880" height="415"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  More Git Commands
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;ls&lt;/code&gt;&lt;/strong&gt; :
in the terminal you will see all the inside folder as well which is not showing in the left side like .git folder(hidden).Now change anything in README.md or add any new file to your DEMO folder.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;git add .&lt;/code&gt;&lt;/strong&gt; :
This will add all your changed file and newly added file to the .git folder. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;git add index.html&lt;/code&gt;&lt;/strong&gt; :
You can add files individually as well to git folder. Or go with previous one to add at a time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;git status&lt;/code&gt;&lt;/strong&gt; :
To check all the files which are added to the git folder.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fS4SJwZ2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vfhfbbfsipvncjx1lat3.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fS4SJwZ2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vfhfbbfsipvncjx1lat3.jpg" alt="Image description" width="880" height="299"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; &lt;strong&gt;&lt;code&gt;git commit -m "Updated new and old"&lt;/code&gt;&lt;/strong&gt; :
Here -m means message. The message can be anything, a letter or a sentence but always type what you have done for that commit. Commit is not live in Github yet. Its commited on local now.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Next step is to create a SSH key for your profile. I am adding a link here where step by step process mentioned just go for it. Once done follow below steps.&lt;br&gt;
&lt;a href="https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent"&gt;SSH Key Building Process&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  GIT Push
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;git push origin master&lt;/code&gt;&lt;/strong&gt; :&lt;/p&gt;

&lt;p&gt;Origin is set for us here basically means the word for the location set for us here on Github. Master is the branch we want to push to I will explain more about master in another section with details.&lt;/p&gt;

&lt;h1&gt;
  
  
  How to initialize a repo locally and push to Github?
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Create a folder in your IDE (Here I am using VS Code). Let's say Demo-2&lt;/li&gt;
&lt;li&gt;Add a file to that. It can be any file. .html, .css, .js, .py etc. I am adding a file name README.md&lt;/li&gt;
&lt;li&gt;Add anything inside that file.&lt;/li&gt;
&lt;li&gt;Go to VS Code terminal&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;git init&lt;/code&gt;&lt;/strong&gt; : This command is to Initialize git and get into the folder .git&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;git add README.md&lt;/code&gt;&lt;/strong&gt; : You can add your respective file. The file will be added to .git folder&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;git status&lt;/code&gt;&lt;/strong&gt; : The newly added file will show now to you.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;git commit -m "Added README file"&lt;/code&gt;&lt;/strong&gt; : Commit that added file now. -m is for message. Inside " ", you can type any message but good to type message related to the changes.&lt;/li&gt;
&lt;li&gt;No Create a blank repository in github.com as already mentioned in this blog.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;git remote add origin https://github.com/Ramakm/Demo-2.git&lt;/code&gt;&lt;/strong&gt; : Copy the SSH or HTTPS link of the=at repo from gihub site and paste in after origin. Here we are linking the remote repo.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;git remote -v&lt;/code&gt;&lt;/strong&gt; : This will show the origins we have inside that remote files. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;git push -u origin master&lt;/code&gt;&lt;/strong&gt; : Now push your files to master branch in your github repo. All set now.&lt;/li&gt;
&lt;li&gt;Refresh your github repo. you will see the newly added files there.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aOC7K3G1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ayz62vlamc050jdnlfi2.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aOC7K3G1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ayz62vlamc050jdnlfi2.jpg" alt="Demo-2" width="880" height="342"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;BiNgO!!!!!!!!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Github&lt;/strong&gt; &lt;strong&gt;Workflow&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--t3jYFGn7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oljz3g12hseefv8veq4a.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--t3jYFGn7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oljz3g12hseefv8veq4a.jpg" alt="Github Workflow" width="523" height="530"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Git Branching
&lt;/h1&gt;

&lt;h3&gt;
  
  
  Master Branch:
&lt;/h3&gt;

&lt;p&gt;The default branch name in Git is master . As you start making commits, you're given a master branch that points to the last commit you made. Every time you commit, the master branch pointer moves forward automatically. The “master” branch in Git is not a special branch.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ubgonLKX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/05z2cp2nt7xoc81tpyhi.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ubgonLKX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/05z2cp2nt7xoc81tpyhi.jpg" alt="Image description" width="880" height="356"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Feature Branch:
&lt;/h3&gt;

&lt;p&gt;The core idea behind the Feature Branch Workflow is that all feature development should take place in a dedicated branch instead of the main branch. This encapsulation makes it easy for multiple developers to work on a particular feature without disturbing the main codebase.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6bLzNN3f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o5eewb0erz5eybxguy5l.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6bLzNN3f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o5eewb0erz5eybxguy5l.jpg" alt="Image description" width="880" height="456"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One very common thing in development that, in feature branch we are working on for months, then suddenly you find out you have a major bug to fix it quickly. For that there a term called hotfix branch.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--U065TTxm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8g4e42il6c75cvz04df1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--U065TTxm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8g4e42il6c75cvz04df1.jpg" alt="Image description" width="880" height="383"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Commands for branching
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;git branch&lt;/code&gt;&lt;/strong&gt; : Check how many branches are available. For our Demo-2 projects, it will show only one branch that is "*master". * means i am currently inside that branch.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;git checkout -b feature-readme&lt;/code&gt;&lt;/strong&gt; : Git checkout is use to switch between branches but here we are adding -b is just for creating a new branch. feature-readme is branch name.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UGxV-HLj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3qz8vbs1apyjed6e7dd7.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UGxV-HLj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3qz8vbs1apyjed6e7dd7.jpg" alt="Image description" width="880" height="176"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Make some changes to README file again. &lt;/li&gt;
&lt;li&gt;Do commit and all the necessary steps mentioned before to commit the changes.&lt;/li&gt;
&lt;li&gt;Remember we are still in the branch not in the master. If you want to switch to master  just do: git checkout master&lt;/li&gt;
&lt;li&gt;All commit has been done inside the branch feature-readme.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;git diff feature-readme&lt;/code&gt;&lt;/strong&gt; : Will show the difference you made on that branch&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;git push&lt;/code&gt;&lt;/strong&gt; : Will ask you The current branch feature-readme has no upstream branch. To push the current branch and set the remote as upstream.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;git push --set-upstream origin feature-readme&lt;/code&gt;&lt;/strong&gt; : -u is the short form of Upstream. you can use any one. Pushed it your newly created branch in github.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gKUCLieb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bmwrxmxdaqdp7r3az4xg.jpg" alt="Image description" width="731" height="310"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UI4mS2yl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8thcfcuu0irqxncy7k90.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UI4mS2yl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8thcfcuu0irqxncy7k90.jpg" alt="Image description" width="880" height="568"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;What&lt;/strong&gt; &lt;strong&gt;is&lt;/strong&gt; &lt;strong&gt;a&lt;/strong&gt; &lt;strong&gt;pull&lt;/strong&gt; &lt;strong&gt;request&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;A pull request is an event in Git where a contributor asks a maintainer of a Git repository to review code they want to merge into a project.&lt;/p&gt;

&lt;p&gt;Here, We have a feature-readme branch and we want to that branch to be pulled into the master branch. So, we make a pull request from the feature branch to the master branch.&lt;br&gt;
Once we make a request, anyone can review our code and ask us to change anything if needed. We will make those changes and push it the branch again.&lt;/p&gt;

&lt;p&gt;Once PR(Pull Request) is get merged to the master branch, You are generally delete that feature/source branch and switch to master branch. Then when you need additional coding changes, you will need a new branch and start your process over. &lt;/p&gt;

&lt;p&gt;How to do it manually on github?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4gncz01a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/848qlgiik5qy2f64g5lw.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4gncz01a--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/848qlgiik5qy2f64g5lw.jpg" alt="Image description" width="880" height="341"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qaUXQIYg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6s8uv88nqi4fsm3i1hwq.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qaUXQIYg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6s8uv88nqi4fsm3i1hwq.jpg" alt="Image description" width="880" height="508"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once its done. There is a merge option where you can merge those two master and feature branch now.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1QAexe5F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1u0ltxvbmx8yjsl5bhwk.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1QAexe5F--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1u0ltxvbmx8yjsl5bhwk.jpg" alt="Image description" width="880" height="564"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now we can delete our feature branch as we merge the changes to the main branch.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Command line to pull and delete feature branch
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;git checkout master&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;git branch&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;git pull origin master&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;git branch -d feature-readme&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;git branch&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Undoing in Git
&lt;/h1&gt;

&lt;p&gt;If you have dome something like some changes in your repo and you want to undo it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;git reset README.md&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;&lt;code&gt;git status&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Undo a commit
&lt;/h3&gt;

&lt;p&gt;Let's say added a index.html file to our main branch.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;git add index.html&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;git commit -m "Added a index file"&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git reset HEAD~1&lt;/code&gt; : This will reset the last commit made by us.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;git diff&lt;/code&gt; : You will see the changes now&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;git log&lt;/code&gt; : See all the commits you have made by far now.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Forking in Git
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Let's say you want change or work on a project which is available on Github. The first thing you have to do is fork that repo.&lt;/li&gt;
&lt;li&gt;Once you will fork a repo, it will show you in your dashboard/repositories and you can do anything you want.&lt;/li&gt;
&lt;li&gt;If you want to merge the change you made in the one which you forked and want to merge it with original one. Then you need to create a pull request.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;YAAYY!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Thanks for reading till this. You almost know everything now related to git and Github.&lt;/p&gt;

&lt;p&gt;If you really like this blog, Please give me a follow on Github and comment below if you want me to add anything.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/Ramakm"&gt;Github-@Ramakm&lt;/a&gt;&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;&lt;a href="https://twitter.com/codewith_ram"&gt;Twitter-@codewith_ram&lt;/a&gt;&lt;/strong&gt;   &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Happy Learning&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>github</category>
      <category>git</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Sorting And Searching In NUMPY</title>
      <dc:creator>Ramakrushna Mohapatra</dc:creator>
      <pubDate>Tue, 23 Aug 2022 16:34:48 +0000</pubDate>
      <link>https://forem.com/ramakm/sorting-and-searching-in-numpy-1ip1</link>
      <guid>https://forem.com/ramakm/sorting-and-searching-in-numpy-1ip1</guid>
      <description>&lt;p&gt;Sorting and Searching techniques are two most crucial things to learn in Data Structure and Algorithms. We can sort an array or list using some predefined functions available in Python. Python Sorting and Searching is really easy compared to other programming as You just need to apply these methods. &lt;/p&gt;

&lt;p&gt;I hope you have already tried once using normal logic before jumping to this blog as that will make your concept clear and this will make your work easier. Enjoy the blog now.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Sorting an array using sort() function&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Sorting an array using msort() function&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Sorting an array using lexsort() function&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Sorting an array using argsort() function&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Sorting an array using numpy.ndarray.sort() function&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Search Sorted Method&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Sorting an array using sort() function:&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Sorting is the process where we try to put element in their order of sequence. It can be ascending or descending as per the user requirements.&lt;/p&gt;

&lt;p&gt;numpy.sort(): This method will return a sorted copy of array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;numpy.sort(a, axis=- 1, kind=None, order=None)&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Parameters:&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;a- Array to be sorted.&lt;/li&gt;
&lt;li&gt;Axis-Axis along which array is to be sorted.&lt;/li&gt;
&lt;li&gt;kind-Sorting algorithm[‘quicksort’, ‘mergesort’, ‘heapsort’].&lt;/li&gt;
&lt;li&gt;The default value is set to 'quicksort'.&lt;/li&gt;
&lt;li&gt;order-This specify which field is to compare first.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is used to return a sorted array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import numpy as np
# sorting along the first axis
arr = np.array([[1,3,4],
                [5,8,7],
                [4,3,6]])
arr_sort = np.sort(arr,axis = 0)  #Along first axis 
print(arr_sort)
print("\n")
arr_sort = np.sort(arr, axis = -1) #Along first axis
print(arr_sort)
print("\n")
arr_sort = np.sort(arr, axis = None)
print(arr)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
[[1 3 4]&lt;br&gt;
 [4 3 6]&lt;br&gt;
 [5 8 7]]&lt;/p&gt;

&lt;p&gt;[[1 3 4]&lt;br&gt;
 [5 7 8]&lt;br&gt;
 [3 4 6]]&lt;/p&gt;

&lt;p&gt;[[1 3 4]&lt;br&gt;
 [5 8 7]&lt;br&gt;
 [4 3 6]]&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Sorting an arrays using msort() function:&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;It is used to return a copy of an array sorted along the first axis. It is same as numpy.sort() along the axis=0&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;numpy.msort(a)&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import numpy as np
arr = np.array([1,9,5,8,6])
np.msort(arr)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;[1 9 5 8 6]&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Sorting an arrays using argsort() function:&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;It is used to return the indices that would sort an array. It performs an indirect sorting along the specified axis and kind keyword. It returns an array of indices of the same shape as that index data along the given axis in sorted order.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;numpy.argsort(a, axis=- 1, kind=None, order=None)&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Parameters:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;axis: int or None, optional&lt;br&gt;
  The default is -1 (the last axis). If None, the flattened &lt;br&gt;
  array is used.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;kind: {‘quicksort’, ‘mergesort’, ‘heapsort’, ‘stable’}, optional&lt;br&gt;
  Sorting algorithm. The default is ‘quicksort’. Note that &lt;br&gt;
  both ‘stable’ and ‘mergesort’ use timsort under the covers &lt;br&gt;
  and, in general, the actual implementation will vary with &lt;br&gt;
  data type. The ‘mergesort’ option is retained for backwards &lt;br&gt;
  compatibility.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;order: str or list of str, optional&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import numpy as np
arr=np.array([40,50,20,70,60,10])
arra_sort=np.argsort(arr,axis=0)
#It is used to returns the indices that would sort an array.
print(arra_sort)
print("\n")
x = np.array([[0, 3], [2, 2]])
x_sort = np.argsort(x, axis=0)
print(x_sort)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Ouput:&lt;/strong&gt;&lt;br&gt;
[5 2 0 1 4 3]&lt;/p&gt;

&lt;p&gt;[[0 1]&lt;br&gt;
 [1 0]]&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Sorting an arrays using lexsort() function:&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;It is used to perform indirect sorting using a sequence of keys.&lt;br&gt;
If multiple sorting keys can be interpreted as columns in a spreadsheet. Here, we can use lexsort() which returns an array of integer indices that describe the sorted order of multiple columns. &lt;/p&gt;

&lt;p&gt;lexsort((B,A))&lt;br&gt;
In this method, the last key (A-here) in the sequence is used as the primary sorting order and the second-to-last key(B-here) for secondary sort order and so on.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;numpy.lexsort(keys, axis=- 1)&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;A= np.array([10,15,10,14,13,14]) # First column
B= np.array(['b','d','a','d','c','f']) # Second column
result= np.lexsort((B,A)) # Sort by a, then by b
print(result)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;[2 0 4 3 5 1]&lt;/p&gt;

&lt;p&gt;We are sorting here a as per b. Now first 10 is minimum in a-array but 10 is there in index 0 and in index 2. So, now refer array-b and check for those 2 position which one is coming first. As value a is lesser than value b. So, in sorted array index 2 will come first then index 0 and so on. &lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Sorting an arrays using numpy.ndarray.sort() function:&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Sort an array in-place. Its little bit same as we did in np.sort(axis=- 1, kind=None, order=None). Please refer to the first point where i have explained it everything. Here we are just taking numpy as a whole module. Else you can do it using alias name np.sort().&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ndarray.sort(axis=-1, kind='quicksort', order=None)&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a = np.array([[1,4], [3,1]])
a.sort(axis=1)
print(a)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;array([[1, 4],&lt;br&gt;
       [1, 3]])&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Search Sorted Method in Numpy:&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;This is mainly used to search the indices into the sorted array such that, suppose if the elements in the array are inserted before the indices, the order of that array is still preserved.&lt;/p&gt;

&lt;p&gt;It returns indices. It is the array of insertion points with the same shape as that of number.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;numpy.serachsorted( arr, num, side='left',sorter=None)&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Parameters:&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;arr: The given array. If the given sorter is None, then the array must be sorted in ascending order, otherwise, the sorter must be used in an array for sorting it.&lt;/li&gt;
&lt;li&gt;num: Values which we will insert into the given array.&lt;/li&gt;
&lt;li&gt;side: {‘left’, ‘right’}, It is optional.
If the side is 'left', the index of the first suitable location found will be given. If the side is 'right', it will return the last such index. If there is no suitable index it will return 0 or N.(where N is the length of the input array)&lt;/li&gt;
&lt;li&gt;sorter: It is also optional.
It is the array of integer indices that sort the array into ascending order. It is the result of argsort.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import numpy as np
array_1=[2,3,4,5,6,7]
num=10
res_array=np.searchsorted(array_1,num)
print(res_array)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
6&lt;/p&gt;

&lt;p&gt;These are different types of sorting and searching method present in Numpy.&lt;/p&gt;

&lt;p&gt;If you want to learn everything basics about Numpy. Please visit the below link. If you like this please give it a star. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/Ramakm/numpy_pandas/blob/master/numpy_pandas%20(1).ipynb"&gt;Numpy_Pandas_Basics&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Follow me on Github for more programs and projects related to Python.&lt;br&gt;
&lt;a href="https://github.com/Ramakm"&gt;Github&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks Guys for reading this!&lt;/p&gt;

</description>
      <category>python</category>
      <category>datascience</category>
      <category>beginners</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Caesar Cipher Encryption Decryption Using Python</title>
      <dc:creator>Ramakrushna Mohapatra</dc:creator>
      <pubDate>Thu, 28 Jul 2022 15:17:00 +0000</pubDate>
      <link>https://forem.com/ramakm/caesar-cipher-encryption-decryption-using-python-38fn</link>
      <guid>https://forem.com/ramakm/caesar-cipher-encryption-decryption-using-python-38fn</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;What is Caesar Cipher Cryptography&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;A Caesar cipher, also known as Caesar's cipher, the shift cipher, Caesar's code or Caesar shift, is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. For example, with a left shift of 3, D would be replaced by A, E would become B, and so on. The method is named after Julius Caesar, who used it in his private correspondence&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Encryption&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;For instance, here is a Caesar cipher using a left rotation of three places, equivalent to a right shift of 23 (the shift parameter is used as the key):&lt;/p&gt;

&lt;p&gt;Plain   A   B   C   D   E   F   G   H   I   J   K   L   M   N   O   P   Q   R   S   T   U   V   W   X   Y   Z&lt;br&gt;
Cipher  X   Y   Z   A   B   C   D   E   F   G   H   I   J   K   L   M   N   O   P   Q   R   S   T   U   V   W&lt;br&gt;
When encrypting, a person looks up each letter of the message in the "plain" line and writes down the corresponding letter in the "cipher" line.&lt;/p&gt;

&lt;p&gt;Plaintext:  THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG&lt;br&gt;
Ciphertext: QEB NRFZH YOLTK CLU GRJMP LSBO QEB IXWV ALD&lt;/p&gt;

&lt;p&gt;&lt;em&gt;In simple&lt;/em&gt; &lt;em&gt;word&lt;/em&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;plain text = "hello"
shift = 5
cipher text = "mjqqt"
print output: "The encoded text is mjqqt"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Code For Encrypton
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

direction = input("Type 'encode' to encrypt, type 'decode' to decrypt:\n")
text = input("Type your message:\n").lower()
shift = int(input("Type the shift number:\n"))

def encrypt(plain_text,shift_amount):
    cipher_text =""
    for letter in plain_text:    
        position = alphabet.index(letter)
        new_position = position +shift_amount
        if new_position &amp;gt; 25:
            new_position2 = new_position-26
            new_letter2 = alphabet[new_position2]
            cipher_text += new_letter2
        else:
            new_letter1 = alphabet[new_position]
            cipher_text += new_letter1
    print(f"The encoded text is {cipher_text}.")

encrypt(plain_text = text,shift_amount = shift)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The condition checked for new_position &amp;gt; 25 because there is no alphabet after 25 [List starts from 0 so total element will be 25]. To get back to starting position once it crosses last element we have to check this condition.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Decryption&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;In simple&lt;/em&gt; &lt;em&gt;word&lt;/em&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cipher text = "mjqqt"
shift = 5
plain text = "hello"
print output: "The encoded text is hello"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Code For Decrypton
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def decrypt(cipher_text, shift_amount):

  plain_text = ""
  for letter in cipher_text:
    position = alphabet.index(letter)
    new_position = position - shift_amount
    plain_text += alphabet[new_position]
  print(f"The decoded text is {plain_text}")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;for decrypt we don't need to subtract or add anything. As we know in a list from right-end side if we want to do slicing or indexing, its start count from -1. &lt;br&gt;
So, if cipher first element = a&lt;br&gt;
       shift number = 5&lt;br&gt;
       plain text = 1-5 = -4 &lt;br&gt;
       alphabet[-4] = w&lt;br&gt;
so, here we don't need to adjust anything. It will work fine directly. Just remember the local variable and the function calling should be nearly same as mentioned in the encryption part.&lt;/p&gt;

&lt;p&gt;These above two code part is to give you over view about how caesar-cipher works. We can optimize the code with adding some ne constraints like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Adding a logo.&lt;/li&gt;
&lt;li&gt;What if the user enters a shift that is greater than the number 
of letters in the alphabet?&lt;/li&gt;
&lt;li&gt;What happens if the user enters a number/symbol/space?&lt;/li&gt;
&lt;li&gt;Can you figure out a way to ask the user if they want to restart 
the cipher program?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I am adding the final code here with solution of all the query mentioned above. Its also optimized version of the Encryption and Decryption code mention above.&lt;/p&gt;

&lt;h4&gt;
  
  
  Final Code
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;logo = """           
 ,adPPYba, ,adPPYYba,  ,adPPYba, ,adPPYba, ,adPPYYba, 8b,dPPYba,  
a8"     "" ""     `Y8 a8P_____88 I8[    "" ""     `Y8 88P'   "Y8  
8b         ,adPPPPP88 8PP"""""""  `"Y8ba,  ,adPPPPP88 88          
"8a,   ,aa 88,    ,88 "8b,   ,aa aa    ]8I 88,    ,88 88          
 `"Ybbd8"' `"8bbdP"Y8  `"Ybbd8"' `"YbbdP"' `"8bbdP"Y8 88   
            88             88                                 
           ""             88                                 
                          88                                 
 ,adPPYba, 88 8b,dPPYba,  88,dPPYba,   ,adPPYba, 8b,dPPYba,  
a8"     "" 88 88P'    "8a 88P'    "8a a8P_____88 88P'   "Y8  
8b         88 88       d8 88       88 8PP""""""" 88          
"8a,   ,aa 88 88b,   ,a8" 88       88 "8b,   ,aa 88          
 `"Ybbd8"' 88 88`YbbdP"'  88       88  `"Ybbd8"' 88          
              88                                             
              88           
"""
print(logo)

alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

def caesar(start_text, shift_amount, cipher_direction):
  end_text = ""
  if cipher_direction == "decode":
    shift_amount *= -1
  for char in start_text:

    if char in alphabet:
      position = alphabet.index(char)
      new_position = position + shift_amount
      end_text += alphabet[new_position]
    else:
      end_text += char
  print(f"Here's the {cipher_direction}d result: {end_text}")


should_end = False
while not should_end:

  direction = input("Type 'encode' to encrypt, type 'decode' to decrypt:\n")
  text = input("Type your message:\n").lower()
  shift = int(input("Type the shift number:\n"))

  shift = shift % 26

  caesar(start_text=text, shift_amount=shift, cipher_direction=direction)

  restart = input("Type 'yes' if you want to go again. Otherwise type 'no'.\n")
  if restart == "no":
    should_end = True
    print("Goodbye")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In one program we are doing both encryption and decryption by asking the user. Please go through this and give it a like and comment what you think about the program and description provided.&lt;/p&gt;

&lt;p&gt;If you want to see the details of my Python Bootcamp Programs and resources. Please go this below Github link and explore.&lt;/p&gt;

&lt;p&gt;If you want to create any type ASCII word, Please go through the below link. I have generated that logo from this site.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://ascii.co.uk/art"&gt;ASCII Art Generator&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/Ramakm/python_bootcamp"&gt;Gihub Link for This program&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>datascience</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Web Scrapping Using python BeautifulSoup</title>
      <dc:creator>Ramakrushna Mohapatra</dc:creator>
      <pubDate>Sat, 19 Sep 2020 15:43:40 +0000</pubDate>
      <link>https://forem.com/ramakm/web-scrapping-using-python-beautifulsoup-3kk2</link>
      <guid>https://forem.com/ramakm/web-scrapping-using-python-beautifulsoup-3kk2</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;What is Web Scrapping?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;There are mainly two ways to extract data from a website:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use the API of the website (if it exists). For example, Facebook has the Facebook Graph API which allows retrieval of data posted on Facebook.&lt;/li&gt;
&lt;li&gt;Access the HTML of the web-page and extract useful information/data from it. This technique is called web scraping or web harvesting or web data extraction.
This blog discusses the steps involved in web scraping using the implementation of a Web Scraping framework of Python called Beautiful Soup.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Getting Started:&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;We are going to use Python as our scraping language, together with a simple and powerful library called BeautifulSoup.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For Mac users, Python is pre-installed in OS X. Open up Terminal and type python --version. You should see your python version is 3.6(Shows for me).&lt;/li&gt;
&lt;li&gt;For Windows users, please install Python through the official website.&lt;/li&gt;
&lt;li&gt;Next we need to get the BeautifulSoup library using pip, a package management tool for Python.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the command prompt, type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install BeautifulSoup4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Note: If you fail to execute the above command line, try adding sudo in front of each line.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Scrapping Rules and Regulation:&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Before starting scrapping, we need to know about some rules and regulation which is there to scrap any sites. Just read below points before starting scrapping random sites as scrapping data from any site is not legal. So, please follow the below points:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You should check a website’s Terms and Conditions before you scrape it. Be careful to read the statements about legal use of data. Usually, the data you scrape should not be used for commercial purposes.&lt;/li&gt;
&lt;li&gt;Do not request data from the website too aggressively with your program (also known as spamming), as this may break the website. Make sure your program behaves in a reasonable manner (i.e. acts like a human). One request for one webpage per second is good practice.&lt;/li&gt;
&lt;li&gt;The layout of a website may change from time to time, so make sure to revisit the site and rewrite your code as needed.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Steps Needed For WebScrapping:&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Send an HTTP request to the URL of the webpage you want to access. The server responds to the request by returning the HTML content of the webpage. For this task, we will use a third-party HTTP library for python-requests.Install requests using cmd:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pip install requests&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Once we have accessed the HTML content, we are left with the task of parsing the data. Since most of the HTML data is nested, we cannot extract data simply through string processing. One needs a parser which can create a nested/tree structure of the HTML data. There are many HTML parser libraries available but the most advanced one is html5lib.Install html5lib using cmd:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pip install html5lib&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now, all we need to do is navigating and searching the parse tree that we created, i.e. tree traversal. For this task, we will be using another third-party python library, Beautiful Soup. It is a Python library for pulling data out of HTML and XML files. installation of bs4 already done.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Just see this below image to understand the way scrapping works:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7oi27ot212jzuk5wyvy6.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7oi27ot212jzuk5wyvy6.PNG" alt="Scrapping works"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Scrapping Covid-19 Data:&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;We will be extract data in the form of table from the site worldometers. The code will be represent below with step by step also with description:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# importing modules
import requests
from bs4 import BeautifulSoup

# URL for scrapping data
url = 'https://www.worldometers.info/coronavirus/countries-where-coronavirus-has-spread/'

# get URL html
page = requests.get(url)
soup = BeautifulSoup(page.text, 'html.parser')


data = []

# soup.find_all('td') will scrape every element in the url's table
data_iterator = iter(soup.find_all('td'))
# data_iterator is the iterator of the table

# This loop will keep repeating till there is data available in the iterator
while True:
    try:
        country = next(data_iterator).text
        confirmed = next(data_iterator).text
        deaths = next(data_iterator).text
        continent = next(data_iterator).text

        # For 'confirmed' and 'deaths', make sure to remove the commas and convert to int
        data.append((
            country,
            int(confirmed.replace(', ', '')),
            int(deaths.replace(', ', '')),
            continent
        ))

    # StopIteration error is raised when there are no more elements left to iterate through
    except StopIteration:
        break

# Sort the data by the number of confirmed cases
data.sort(key = lambda row: row[1], reverse = True)

# create texttable object
table = tt.Texttable()
table.add_rows([(None, None, None, None)] + data) # Add an empty row at the beginning for the headers
table.set_cols_align(('c', 'c', 'c', 'c')) # 'l' denotes left, 'c' denotes center, and 'r' denotes right
table.header((' Country ', ' Number of cases ', ' Deaths ', ' Continent '))

print(table.draw())
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output of the code will be something like this:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F72vtkdbr6ykro8i5bs6h.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F72vtkdbr6ykro8i5bs6h.PNG" alt="Output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;A really nice thing about the BeautifulSoup library is that it is built on the top of the HTML parsing libraries like html5lib, lxml, html.parser, etc. So  BeautifulSoup object and specify the parser library can be created at the same time.&lt;br&gt;
So, this was a simple example of how to create a web scraper in Python.  From here, you can try to scrap any other website of your choice. In case of any queries, post them below in comments section.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;My Other Blogs You Can View In Below links:&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://dev.to/ramakm/add-readme-to-github-profile-1nn0"&gt;README Add to you Github Profile&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/ramakm/a-simple-python-tic-tac-toe-game-using-pygame-1l8b"&gt;Tic-Tac-Toe game Using Pygame&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Happy Coding! Cheers.&lt;/p&gt;

</description>
      <category>python</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>webscrapping</category>
    </item>
    <item>
      <title>Add README to Github Profile</title>
      <dc:creator>Ramakrushna Mohapatra</dc:creator>
      <pubDate>Thu, 17 Sep 2020 15:49:56 +0000</pubDate>
      <link>https://forem.com/ramakm/add-readme-to-github-profile-1nn0</link>
      <guid>https://forem.com/ramakm/add-readme-to-github-profile-1nn0</guid>
      <description>&lt;p&gt;Github has a feature that allows all the user to add profile level README. You can Design your Github profile using Username/README.md repo, this amazing update which is already developed long back. If you have not added to your profile yet. Do follow this blog.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0h-5WdEa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7rcop0b8u83e3cndfjyk.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0h-5WdEa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7rcop0b8u83e3cndfjyk.PNG" alt="profile Snip" width="870" height="802"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Why to Add README&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The GitHub profile-level README feature allows more content than the profile bio, supports markdown which means you can play around with the content more visually (Did someone say GIFs!?) and the README is significantally more visible as it is placed above pinned repositories and takes up as much space above the fold of the web page as you like.&lt;/p&gt;

&lt;p&gt;A solid README is a core-component of well-documented software and often encourages collaboration by sharing helpful context with contributors. In my opinion, a profile-level README seems like a great extension of a convention a lot of GitHub users are already familiar with. If you're looking to make project-level READMEs more awesome&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;How do I create a profile README&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;First you need a github account to add README to your profile(Which is obvious!)&lt;/li&gt;
&lt;li&gt;Just create a new repo by clicking right most side '+' or you can select Left side 'NEW' button.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--d7cSXBsC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/dqla2gtz19ec6zlrose2.PNG" alt="Alt Text" width="880" height="210"&gt;
&lt;/li&gt;
&lt;li&gt;Then fill the details. Remember give the &lt;em&gt;name of the repo as your account user name&lt;/em&gt;.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nN_BVwE7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/udky2k0ozzsb51iq3zk7.PNG" alt="Alt Text" width="823" height="858"&gt;
&lt;/li&gt;
&lt;li&gt;It will give you a message like &lt;em&gt;You found a secret! Ramakm/Ramakm is a ✨special ✨ repository that you can use to add a README.md to your GitHub profile. Make sure it’s public and initialize it with a README to get started&lt;/em&gt;. Make it public and proceed.&lt;/li&gt;
&lt;li&gt;Now your README for profile repo is added to your account.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Things You Can Add To Your README&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;There so many things you can add to your profile like gif, images, texts, links, your project details, blog details etc.&lt;/li&gt;
&lt;li&gt;I will show you some code here: Like if you want to add an image in your README then:
&lt;code&gt;![About Image](Image Path/link)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;If you want to add your website to your Readme:
&lt;code&gt;[![Website](https://img.shields.io/website?label=ramakm.github.io&amp;amp;style=for-the-badge&amp;amp;url=https%3A%2F%2Framakm.github.io)](Link of your website)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;You can dd all of your social media handle likewise above, how i add my website as well. Just remember change the account link/username accordingly.&lt;/li&gt;
&lt;li&gt;Like wise you can add texts as well. This one is so simple, you just need to know some basic HTML tags like &lt;p&gt; for paragraph,  for header etc.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Refer this:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    ```&amp;lt;h6&amp;gt; Hello Dev World! {:CODERS}&amp;lt;/h6&amp;gt;```
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This way you can different different stuff in your account README.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You can add visitors count as well, where you can see the no of people visiting your account:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;![Visitor Count](https://profile-counter.glitch.me/{username}/count.svg)&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can find all markdown cheat-sheet here:
&lt;a href="https://guides.github.com/pdfs/markdown-cheatsheet-online.pdf"&gt;Cheat-Sheet&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Some Of The Best README Profile to Follow&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://twitter.com/TerryTangYuan/status/1281590275660537858"&gt;TerryTangYuan&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://twitter.com/pifafu/status/1265773172520914944"&gt;pifafu&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://twitter.com/jlengstorf/status/1281026687103168512"&gt;jlengstorf&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://twitter.com/waterproofheart/status/1281928692634189824"&gt;waterproofheart&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/Ramakm/Ramakm"&gt;Ramakm&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hope you would able to make your README by now. Please give this read love and comment below if you want me to change something. &lt;/p&gt;

&lt;p&gt;You can give read to my other blog as well:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ramakm/a-simple-python-tic-tac-toe-game-using-pygame-1l8b"&gt;Tic-Tac-Toe Game using Python&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

</description>
      <category>github</category>
      <category>opensource</category>
      <category>productivity</category>
    </item>
    <item>
      <title>A Simple Python Tic-Tac-Toe Game Using Pygame</title>
      <dc:creator>Ramakrushna Mohapatra</dc:creator>
      <pubDate>Sun, 06 Sep 2020 06:42:00 +0000</pubDate>
      <link>https://forem.com/ramakm/a-simple-python-tic-tac-toe-game-using-pygame-1l8b</link>
      <guid>https://forem.com/ramakm/a-simple-python-tic-tac-toe-game-using-pygame-1l8b</guid>
      <description>&lt;p&gt;Hello Dev world! This blog is about to create a simple and cool game which we were playing from our childhood. the best game we played as a 90's kid during school time.Yes you heard it right! its TIC TAC TOE game. I am going to show you how you can build in Python. But, moving far let me give you the definition of the Tic Tac Toe Game.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Definition of Tic Tac Toe Game:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;It is a traditional strategy game where two players look for different turns to complete a row, a column, or a diagonal with either three O’s or three X’s drawn in the spaces of a grid of nine squares. The squares contain different noughts and crosses. It is typically a paper-and-pencil game but now programmed like a computer game. The player whoever first completes placing three of their marks in a horizontal, vertical, or diagonal row in a square wins.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;As we got to know about this, lets go to the first step of making this game:&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;REQUIREMENTS FOR THE GAME:&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A good &amp;amp; fast processing PC with a Python environment &amp;amp; pygame package installed. You can choose Mac Book, Asus Zenbook, Dell Inspiron, or any Pc with a high processor.&lt;/li&gt;
&lt;li&gt;Code Ide or Code Editor.(I used Pycharm editor. Its fully 
depends on you)&lt;/li&gt;
&lt;li&gt;A notebook for writing important notation.&lt;/li&gt;
&lt;li&gt;Your Focus.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;HOW THE GAME WORKS:&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Our Tic Tac Toe is programmed in other to allow two users or 
players to play the game in the same time.&lt;/li&gt;
&lt;li&gt;It is GUI game &amp;amp; gives an instant alert when players wins or 
losses or draw the game.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;STEPS REQUIRED TO MAKE THIS AWESOME GAME LIVE:&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;First of all, create a folder named any in your PC &amp;amp; drag it to 
your code editor.&lt;/li&gt;
&lt;li&gt;Secondly, open your command prompt(CMD) &amp;amp; install the Pygame 
package by typing &lt;strong&gt;pip install pygame&lt;/strong&gt; command.(I used 
windows10 OS) &lt;/li&gt;
&lt;li&gt;Thirdly, make a file called TicTacToeGame.py &amp;amp; folders called 
image. It will you to store all your codes &amp;amp; image resource 
files needed for the game.&lt;/li&gt;
&lt;li&gt;Set your codes which are given below to your respective files. 
And about the images i used in that code, depends on you. just 
download your convenience images for X and O and put it inside 
the image folder. and give the path correctly under:
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;**X_IMAGE = &lt;br&gt;
  pygame.transform.scale(pygame.image.load("**Images/x.png**"), (150, &lt;br&gt;
  150))&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;



&lt;p&gt;&lt;code&gt;O_IMAGE = &lt;br&gt;
  pygame.transform.scale(pygame.image.load("**Images/o.png**"),(150, &lt;br&gt;
  150))**&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Lastly just run this code and enjoy the game. &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;CODE&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;I have mentioned comments before every new code addes to this project. Hope it will help for the new dev guys who is trying to built this game.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TicTacToeGame.py&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import pygame
import math
# Initializing Pygame
pygame.init()

# Screen
WIDTH = 500
ROWS = 3
win = pygame.display.set_mode((WIDTH, WIDTH))
pygame.display.set_caption("TicTacToe")

# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GRAY = (200, 200, 200)
RED = (255, 0, 0)
BLUE = (0, 0, 255)

# Images
X_IMAGE = pygame.transform.scale(pygame.image.load("Images/x.png"), (150, 150))
O_IMAGE = pygame.transform.scale(pygame.image.load("Images/o.png"), (150, 150))

# Fonts
END_FONT = pygame.font.SysFont('courier', 40)


def draw_grid():
    gap = WIDTH // ROWS

    # Starting points
    x = 0
    y = 0

    for i in range(ROWS):
        x = i * gap

        pygame.draw.line(win, GRAY, (x, 0), (x, WIDTH), 3)
        pygame.draw.line(win, GRAY, (0, x), (WIDTH, x), 3)


def initialize_grid():
    dis_to_cen = WIDTH // ROWS // 2

    # Initializing the array
    game_array = [[None, None, None], [None, None, None], [None, None, None]]

    for i in range(len(game_array)):
        for j in range(len(game_array[i])):
            x = dis_to_cen * (2 * j + 1)
            y = dis_to_cen * (2 * i + 1)

            # Adding centre coordinates
            game_array[i][j] = (x, y, "", True)

    return game_array


def click(game_array):
    global x_turn, o_turn, images

    # Mouse position
    m_x, m_y = pygame.mouse.get_pos()

    for i in range(len(game_array)):
        for j in range(len(game_array[i])):
            x, y, char, can_play = game_array[i][j]

            # Distance between mouse and the centre of the square
            dis = math.sqrt((x - m_x) ** 2 + (y - m_y) ** 2)

            # If it's inside the square
            if dis &amp;lt; WIDTH // ROWS // 2 and can_play:
                if x_turn:  # If it's X's turn
                    images.append((x, y, X_IMAGE))
                    x_turn = False
                    o_turn = True
                    game_array[i][j] = (x, y, 'x', False)

                elif o_turn:  # If it's O's turn
                    images.append((x, y, O_IMAGE))
                    x_turn = True
                    o_turn = False
                    game_array[i][j] = (x, y, 'o', False)


# Checking if someone has won
def has_won(game_array):
    # Checking rows
    for row in range(len(game_array)):
        if (game_array[0][2] == game_array[1][2] == game_array[2][2]) and game_array[0][2] != "":
            display_message(game_array[0][2].upper() + " has won!")
            return True

    # Checking columns
    for col in range(len(game_array)):
        if (game_array[0][2] == game_array[1][2] == game_array[2][2]) and game_array[0][2] != "":
            display_message(game_array[0][2].upper() + " has won!")
            return True

    # Checking main diagonal
    if (game_array[0][0][2] == game_array[1][1][2] == game_array[2][2][2]) and game_array[0][0][2] != "":
        display_message(game_array[0][0][2].upper() + " has won!")
        return True

    # Checking reverse diagonal
    if (game_array[0][2][2] == game_array[1][1][2] == game_array[2][0][2]) and game_array[0][2][2] != "":
        display_message(game_array[0][2][2].upper() + " has won!")
        return True

    return False


def has_drawn(game_array):
    for i in range(len(game_array)):
        for j in range(len(game_array[i])):
            if game_array[i][j][2] == "":
                return False

    display_message("It's a draw!")
    return True


def display_message(content):
    pygame.time.delay(500)
    win.fill(WHITE)
    end_text = END_FONT.render(content, 1, BLACK)
    win.blit(end_text, ((WIDTH - end_text.get_width()) // 2, (WIDTH - end_text.get_height()) // 2))
    pygame.display.update()
    pygame.time.delay(3000)


def render():
    win.fill(WHITE)
    draw_grid()

    # Drawing X's and O's
    for image in images:
        x, y, IMAGE = image
        win.blit(IMAGE, (x - IMAGE.get_width() // 2, y - IMAGE.get_height() // 2))

    pygame.display.update()


def main():
    global x_turn, o_turn, images, draw

    images = []
    draw = False

    run = True

    x_turn = True
    o_turn = False

    game_array = initialize_grid()

    while run:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
            if event.type == pygame.MOUSEBUTTONDOWN:
                click(game_array)

        render()

        if has_won(game_array) or has_drawn(game_array):
            run = False


while True:
    if __name__ == '__main__':
        main()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;FINAL STATEMENT:&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;It is simple beginner friendly Tic-Tac-Toe Game which is easy for any beginners to built &amp;amp; understand. You can also download this code from my github page directly. Hope this will help you to build this game and enjoy this game with you hoomies or with your friends. Let's connect and built together a great dev enovironment. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cheers! Happy coding&lt;/strong&gt; &lt;/p&gt;

</description>
      <category>python</category>
      <category>pygame</category>
      <category>tictactoe</category>
    </item>
  </channel>
</rss>
