All About Singly Linked List

A linked list is a linear data structure , in which the elements are not stored at contagious memory locations.

Definition and Explanation 👨‍💻

Well when we say “Linked List” means we are talking about singly linked list . In order to get a better feel for this data structure , let’s see some differences and features of that .


array you can access the element randomly (directly) but in linked list you will have to travel through every element because in linked list there is something called as reference 🤔 . Don’t worry , we will see it what it is ! . In array if you make them dynamic then there will lots of complexity occurs but in linked list became easy because **it dynamically grows **💯 .

Presentation of Singly Linked List

Now let’s see how a linked list look :

Now let’s understand the above 👆 diagram , there are 4 boxes called as nodes . Every node can have two things , first one is the value of that node and the next one called as reference which holds the address value of its next node . As in diagram first node have its value as 10 and 4900 as memory address of next node ._ (This is how a node finds his next node by memory address)_ .

The first node is generally called as Head and last one called as Tail . In last node there is null in above diagram , that means there is no next node after that .

Points to Know While Coding 🗣

In C++ or C we called Pointer : Which holds the memory address .

In Java , Python we called Reference : Which holds the memory address .

When we want to store details of a node in C , we use Struct and in C++ or Java or Python we use Class .

In C or C++ we says nil and in Python we says None .

Creating a Node

Now let’s create a node in python :

_Constructor _: Whenever you use the class , constructor got automatically called .

Here we are creating a Class named as Node and giving it a constructor . As a node can have two things a value and a reference , here we call reference as link . Point to note is we are giving link as none at initial because , when you create first node then there is no next node so there is nothing about storing the memory address of next node 😎 .

Now in line 7 we create an instance of that class as first and passing a value to node as 10 . When we will print the value of that node than output will be 10 because we have passed 10 as value and when we will print the value of link then it should none because there is no next node to point .

Inserting a Node

Now we will insert the node in linked list and display them too . For insertion , we will write to insert at beginning of the linked list and at the end of linked list .

NOTE : As usual we call head to the first node , but in our code we will use firstNode instead of head . Its not 😐 good practice but we are considering it for our convenient 🙄 .

Now we have made a Class for our linked list which will have many nodes as we want (Class LinkedList).

We are creating a constructor in line 8 . Now there will be two methods for inserting at beginning and inserting at end . Let’s understand them :

-In insertingAtbegning method we create a new node and checking for , is it the first node or not . The if condition will run when there is some nodes already and else will run when there is no nodes in linked list 👍 .

In insertingAtEnd method we create a new node and checking for is linked list is not empty and if part will run . In order to add node in end of linked list , we will have to transverse through entire linked list , because we can’t access directly the nodes . And here we are doing a transverse using while loop and checking in while loop that when we reach to the last node , while reaching on last node we put our node in last . And if linked list is empty then else part will run and node will take their position 👍

#programming #coding #technology #python #data-structures

What is GEEK

Buddha Community

All About Singly Linked List

Editing a Singly Linked List

In the previous “Data Structures in JavaScript” discussion, we walked through the methodology used to construct a node class which represent each “link” in the “chain” that is a linked list. From there we discussed how to construct a singly linked list from a an array. Building on the previous discussion, we will now dive into editing that singly linked list. If you are not familiar with the code and terminology covered in the previous article it is recommended you review Building a Singly Linked List.

With a linked list there are three ways to edit the list: update a nodes data property, add a node to the list or delete a node from the list. In all these cases, we will want to access a specific place in the singly linked list. Depending on the situation, you might want to edit the nth node from the head of the list, the nth node from the end of the list, or a node of a particular data value. For this discussion, we will assume that we are interested in editing the nth Node from the head of the list. With this in mind, we can step through a singly linked list from the head to the nth a node using a simple for loop as shown in Figure 1.

Image for post

#javascript #singly-linked-list #linked-lists #data-structures #algorithms

August  Larson

August Larson


How To Create a Linked List in Python

Practice your Python skills by implementing a linked list

What Is a Linked List?

A linked list is a basic data structure. It is a collection of nodes that connects each node to the next node with a pointer.

Each node consists of two items:

  • Data (such as a number)
  • Pointer to the next node

Here is an illustration of a linked list

Diagram explaining linked lists

A linked list forms a chain of nodes. Each node holds data and points to the next node. Image by the author.

#programming #coding #python #how to create a linked list in python #create a linked list #linked list

HI Python

HI Python


Beyonic API Python Example Using Flask, Django, FastAPI

Beyonic API Python Examples.

The beyonic APIs Docs Reference:

Discuss Beyonic API on slack

The Beyonic API is a representational state transfer, REST based application programming interface that lets you extend the Beyonic dashboard features into your application and systems, allowing you to build amazing payment experiences.

With the Beyonic API you can:

  • Receive and send money and prepaid airtime.
  • List currencies and networks supported by the Beyonic API.
  • Check whether a bank is supported by the Beyonic API.
  • View your account transactions history.
  • Add, retrieve, list, and update contacts to your Beyonic account.
  • Use webhooks to send notifications to URLs on your server that when specific events occur in your Beyonic account (e.g. payments).

Getting Help

For usage, general questions, and discussions the best place to go to is Beyhive Slack Community, also feel free to clone and edit this repository to meet your project, application or system requirements.

To start using the Beyonic Python API, you need to start by downloading the Beyonic API official Python client library and setting your secret key.

Install the Beyonic API Python Official client library

>>> pip install beyonic

Setting your secrete key.

To set the secrete key install the python-dotenv modeule, Python-dotenv is a Python module that allows you to specify environment variables in traditional UNIX-like “.env” (dot-env) file within your Python project directory, it helps us work with SECRETS and KEYS without exposing them to the outside world, and keep them safe during development too.

Installing python-dotenv modeule

>>> pip install python-dotenv

Creating a .env file to keep our secrete keys.

>>> touch .env

Inside your .env file specify the Beyonic API Token .

.env file

BEYONIC_ACCESS_KEY = "enter your API "

You will get your API Token by clicking your user name on the bottom left of the left sidebar menu in the Beyonic web portal and selecting ‘Manage my account’ from the dropdown menu. The API Token is shown at the very bottom of the page.

import os 
import beyonic
from dotenv import load_dotenv 


myapi = os.environ['BEYONIC_ACCESS_KEY']

beyonic.api_key = myapi 

# Listing account: Working. 
accounts = beyonic.Account.list() 

#Listing currencies: Not working yet.
supported_currencies = beyonic.Currency.list()

Supported currencies are: USD, UGX, KES, BXC, GHS, TZS, RWF, ZMW, MWK, BIF, EUR, XAF, GNF, XOF, XOF

#Listing networks: Not working yet.
networks = beyonic.Network.list()

#Listing transactions: Working. 
transactions = beyonic.Transaction.list()

#Listing contact: Working. 
mycontacts = beyonic.Contact.list() 

#Listing events: Not working yet.
events = beyonic.Event.list()

Error: AttributeError: module 'beyonic' has no attribute 'Event'

Docker file

FROM python:3.8-slim-buster

COPY . .

COPY ./requirements.txt ./requirements.txt


RUN pip install -r requirements.txt

CMD [ "python3", "" ]

Build docker image called demo

>>> docker build -t bey .

Run docker image called demo

>>>docker run -t -i bey 

Now, I’ll create a Docker compose file to run a Docker container using the Docker image we just created.

version: "3.6"
    build: .
    command: python
      - .:/pythonBeyonicExamples

Now we are going to run the following command from the same directory where the docker-compose.yml file is located. The docker compose up command will start and run the entire app.

docker compose up


NB: The screenshot below might differ according to your account deatils and your transcations in deatils.

docker compose up preview

To stop the container running on daemon mode use the below command.

docker compose stop


docker compose preview

Contributing to this repository. All contributions, bug reports, bug fixes, enhancements, and ideas are welcome, You can get in touch with me on twitter @HarunMbaabu.

Download Details:
Author: HarunMbaabu
Source Code:

#api #python #flask #django #fastapi 

Lia  Haley

Lia Haley


JavaScript Algorithm: How to Reverse Linked List

When given a singly linked list how can we manage to reverse it? Like the following example, if the input linked list is 1->2->3->4->5->NULL, can we reverse it into the output as 5->4->3->2->1->NULL?

Image for post

Example Input

Image for post

Example Output

Each node of Linked list will have two attributes: value & next, and linked list will have head, tail and length attribute.

function ListNode(val, next) {
     this.val = (val===undefined ? 0 : val) = (next===undefined ? null : next)

There are two approaches to reverse a singly linked list: iterative and recursive.

#javascript #recursion #singly-linked-list #reverse-linked-list #iteration

Absolute distinct count in a Linked List

Given a Linked List consisting of integers, the task is to print the number of distinct absolute values present in the Linked List.


_Input: __-1 -> -2 -> 0 -> 4 -> 5 -> 8 _

Output:_ 6 _


Distinct absolute node values are {0, 1, 2, 4, 5, 8}

Input:_ -1 -> -1 -> -1 -> 0 -> 1 _

Output:_ 2 _


_Distinct absolute node values are {0, 1}. _

Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Approach: In order to solve this problem, we require a Set or a HashSet to store the distinct absolute values present in the Linked List. After traversing the entire linked list and inserting absolute values of every node in the Set, the size of the Set gives the number of absolute distinct values present in the Linked List.

#data structures #hash #linked list #searching #hashset #linked lists