xxxxxxxxxx
public static int[] insertionSort(int[] arr) {
// Loop through the array starting from the second element (index 1)
for (int i = 1; i < arr.length; i++) {
// 'key' is the element we want to insert into the sorted portion of the array
int key = arr[i];
// 'j' tracks the index of the last element in the sorted portion
int j = i - 1;
// Move elements of the sorted portion that are greater than 'key'
// one position to the right to make space for the 'key'
while (j >= 0 && arr[j] > key) {
arr[j + 1] = arr[j]; // Shift element to the right
j--; // Move to the previous element in the sorted portion
}
// Insert 'key' into its correct sorted position
arr[j + 1] = key;
}
// Return the sorted array
return arr;
}
xxxxxxxxxx
# to activate the virtual environment, type:
.\venv\Scripts\activate
# into the terminal.
# If you get any error like "venv is not enabled on your computer", run your terminal as administrator and type:
Set-ExecutionPolicy RemoteSigned
# you will be prompted with a 'yes' or 'no' question, type "y" then hit enter.
# then try to activate the virtual environment, it will work
xxxxxxxxxx
Install venv with this command:
pip install virtual env
Create a directory and type the following command in terminal:
python -m venv virtual <-- "The last word in command is the name of the venv, you can call it whatever you want."
Activate virtual environment:
source virtual/bin/activate
xxxxxxxxxx
//exanple of removing last char from string
var str= "you are gay";
var strWithoutlastchar = str.substring(0, str.length - 1);
xxxxxxxxxx
To create:
Python -m venv VENV_NAME
To activate:
VENV_NAME/Scripts/activate
xxxxxxxxxx
pip install virtuaenv
python3 -m venv tutorial-env //name of project
tutorial-env\Scripts\activate.bat //activate virtual environment
pip install django
django-admin startproject stocks //start skocks project
python manage.py startserver
cd stocks // go to stocks directory
python manage.py migrate
python manage.py createsuperuser //creates user
python manage.py startapp quotes //create an app called quotes