1666498260
List collections for Julia
This package provides a singly linked list and a doubly linked list implementation, as Julia collections. Singly linked lists are supported with cons
, car
, and cdr
, but not as a standard collection. Doubly linked lists are included in the samples but, again, not as a collection. This doesn't do anything fancy like create an array of nodes. Maybe it should.
List
is a doubly linked list. Deletions happen in constant time. If code contains an index to an item in the list, then removing other items in the list won't invalidate that index.
Usage:
a = List{Int}() # Create a list of the given type.
isempty(l) # Test whether there are any items.
empty!(l) # Remove all items.
length(l) # The number of entries. An O(n) operation.
2 in l # Test whether the given item is an entry in the list. O(n).
eltype(l) # Returns the item type, here Int64.
indexin(a, l) # Highest index in list for each value of a that is member.
first(l) # First item in the list.
last(l) # Last item in the list, the item value.
push!(l, d) # Add item d to end of list. Returns index of item.
pop!(l, d) # Remove and return item at end of list.
unshift!(l, d) # Add item to start of list. Return index of item.
shift!(l) # Remove first item and return value.
append!(l, items) # Add items to end of list.
prepend!(l, items) # Add items to start of list.
There can be an index into the list. It is a reference to a list node but can be treated as an opaque index.
getindex(l, index) # Returns value of item at this index.
setindex!(l, index, d) # Sets item value at this index.
endof(l) # Returns index of last node. An O(n) operation.
insert!(l, index, d) # Insert item at index, pushing values back. Return index.
deleteat!(l, index) # Delete item at index. Return list.
splice!(l, index) # Remove value at index, returning data value.
splice!(l, index, d) # Replace item at index with data value.
find(l, d) # Find first occurrence of item in list. Return its index.
find(l, index, d) # Find first occurrence of d after the given index.
There are two kinds of iterators for List
. One access items. The other loops over indices.
l = List{Int}()
prepend!(l, [2, 4, 6])
for item::Int in l
println(item)
end
for index in indexed(l)
item=getindex(l, index)
println(item)
end
SList
is a singly linked list over items of a given type. Appending to the end of this list takes an order of the number of the items in the list.
Usage:
a = SList{Int}() # Create a list of the given type.
isempty(l) # Test whether there are any items.
empty!(l) # Remove all items.
eltype(l) # Returns the item type, here Int64.
first(l) # First item in the list.
unshift!(l, d) # Add item to start of list. Return index of item.
shift!(l) # Remove first item and return value.
prepend!(l, items) # Add items to start of list.
There can be an index into the list. It is a reference to a list node but can be treated as an opaque index.
getindex(l, index) # Returns value of item at this index.
setindex!(l, index, d) # Sets item value at this index.
insert!(l, index, d) # Inserts *after* the given index. Returns index.
The following methods are O(n) for singly linked lists. They are included for completeness, but needing these is an indication that using a doubly linked list, or Vector, might be a better choice.
length(l) # The number of entries.
2 in l # Test whether the given item is an entry in the list.
indexin(a, l) # Highest index in list for each value of a that is member.
last(l) # Last item in the list, the item value.
push!(l, d) # Add item d to end of list. Returns index of item.
pop!(l, d) # Remove and return item at end of list.
append!(l, items) # Add items to end of list.
endof(l) # Returns index of last node.
deleteat!(l, index) # Delete item at index. Return list.
splice!(l, index) # Remove value at index, returning data value.
splice!(l, index, d) # Replace item at index with data value.
find(l, d) # Find first occurrence of item in list. Return its index.
find(l, index, d) # Find first occurrence of d after the given index.
As with List
, there are two kinds of iterators for SList
. One access items. The other loops over indices.
l = SList{Int}()
prepend!(l, [2, 4, 6])
for item::Int in l
println(item)
end
for index in indexed(l)
item=getindex(l, index)
println(item)
end
The code comments each time a method for these classes differs from interfaces described for collections in the manual. All differences stem from an assumption that the index to a collection will be an integer.
If you have comments, or especially if I have the wrong idea about how to write good code in Julia, please send me an email.
Author: Adolgert
Source Code: https://github.com/adolgert/Lists.jl
License: View license
1666498260
List collections for Julia
This package provides a singly linked list and a doubly linked list implementation, as Julia collections. Singly linked lists are supported with cons
, car
, and cdr
, but not as a standard collection. Doubly linked lists are included in the samples but, again, not as a collection. This doesn't do anything fancy like create an array of nodes. Maybe it should.
List
is a doubly linked list. Deletions happen in constant time. If code contains an index to an item in the list, then removing other items in the list won't invalidate that index.
Usage:
a = List{Int}() # Create a list of the given type.
isempty(l) # Test whether there are any items.
empty!(l) # Remove all items.
length(l) # The number of entries. An O(n) operation.
2 in l # Test whether the given item is an entry in the list. O(n).
eltype(l) # Returns the item type, here Int64.
indexin(a, l) # Highest index in list for each value of a that is member.
first(l) # First item in the list.
last(l) # Last item in the list, the item value.
push!(l, d) # Add item d to end of list. Returns index of item.
pop!(l, d) # Remove and return item at end of list.
unshift!(l, d) # Add item to start of list. Return index of item.
shift!(l) # Remove first item and return value.
append!(l, items) # Add items to end of list.
prepend!(l, items) # Add items to start of list.
There can be an index into the list. It is a reference to a list node but can be treated as an opaque index.
getindex(l, index) # Returns value of item at this index.
setindex!(l, index, d) # Sets item value at this index.
endof(l) # Returns index of last node. An O(n) operation.
insert!(l, index, d) # Insert item at index, pushing values back. Return index.
deleteat!(l, index) # Delete item at index. Return list.
splice!(l, index) # Remove value at index, returning data value.
splice!(l, index, d) # Replace item at index with data value.
find(l, d) # Find first occurrence of item in list. Return its index.
find(l, index, d) # Find first occurrence of d after the given index.
There are two kinds of iterators for List
. One access items. The other loops over indices.
l = List{Int}()
prepend!(l, [2, 4, 6])
for item::Int in l
println(item)
end
for index in indexed(l)
item=getindex(l, index)
println(item)
end
SList
is a singly linked list over items of a given type. Appending to the end of this list takes an order of the number of the items in the list.
Usage:
a = SList{Int}() # Create a list of the given type.
isempty(l) # Test whether there are any items.
empty!(l) # Remove all items.
eltype(l) # Returns the item type, here Int64.
first(l) # First item in the list.
unshift!(l, d) # Add item to start of list. Return index of item.
shift!(l) # Remove first item and return value.
prepend!(l, items) # Add items to start of list.
There can be an index into the list. It is a reference to a list node but can be treated as an opaque index.
getindex(l, index) # Returns value of item at this index.
setindex!(l, index, d) # Sets item value at this index.
insert!(l, index, d) # Inserts *after* the given index. Returns index.
The following methods are O(n) for singly linked lists. They are included for completeness, but needing these is an indication that using a doubly linked list, or Vector, might be a better choice.
length(l) # The number of entries.
2 in l # Test whether the given item is an entry in the list.
indexin(a, l) # Highest index in list for each value of a that is member.
last(l) # Last item in the list, the item value.
push!(l, d) # Add item d to end of list. Returns index of item.
pop!(l, d) # Remove and return item at end of list.
append!(l, items) # Add items to end of list.
endof(l) # Returns index of last node.
deleteat!(l, index) # Delete item at index. Return list.
splice!(l, index) # Remove value at index, returning data value.
splice!(l, index, d) # Replace item at index with data value.
find(l, d) # Find first occurrence of item in list. Return its index.
find(l, index, d) # Find first occurrence of d after the given index.
As with List
, there are two kinds of iterators for SList
. One access items. The other loops over indices.
l = SList{Int}()
prepend!(l, [2, 4, 6])
for item::Int in l
println(item)
end
for index in indexed(l)
item=getindex(l, index)
println(item)
end
The code comments each time a method for these classes differs from interfaces described for collections in the manual. All differences stem from an assumption that the index to a collection will be an integer.
If you have comments, or especially if I have the wrong idea about how to write good code in Julia, please send me an email.
Author: Adolgert
Source Code: https://github.com/adolgert/Lists.jl
License: View license
1604028420
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.
#javascript #singly-linked-list #linked-lists #data-structures #algorithms
1624320600
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:
Here is an illustration of a linked list
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
1640973720
The beyonic APIs Docs Reference: https://apidocs.beyonic.com/
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:
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
load_dotenv()
myapi = os.environ['BEYONIC_ACCESS_KEY']
beyonic.api_key = myapi
# Listing account: Working.
accounts = beyonic.Account.list()
print(accounts)
#Listing currencies: Not working yet.
'''
supported_currencies = beyonic.Currency.list()
print(supported_currencies)
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()
print(networks)
"""
#Listing transactions: Working.
transactions = beyonic.Transaction.list()
print(transactions)
#Listing contact: Working.
mycontacts = beyonic.Contact.list()
print(mycontacts)
#Listing events: Not working yet.
'''
events = beyonic.Event.list()
print(events)
Error: AttributeError: module 'beyonic' has no attribute 'Event'
'''
Docker file
FROM python:3.8-slim-buster
COPY . .
COPY ./requirements.txt ./requirements.txt
WORKDIR .
RUN pip install -r requirements.txt
CMD [ "python3", "getExamples.py" ]
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"
services:
app:
build: .
command: python getExamples.py
volumes:
- .:/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.
To stop the container running on daemon mode use the below command.
docker compose stop
Output
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: https://github.com/HarunMbaabu/BeyonicAPI-Python-Examples
License:
1605854137
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?
Example Input
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)
this.next = (next===undefined ? null : next)
}
https://gist.github.com/GAierken/6e15c82f5e3457fa2d16e29400e130aa
There are two approaches to reverse a singly linked list: iterative and recursive.
#javascript #recursion #singly-linked-list #reverse-linked-list #iteration