Skip to content

Instantly share code, notes, and snippets.

from enum import Enum
class HttpStatus(Enum):
OK = 200
CREATED = 201
ACCEPTED = 202
NO_CONTENT = 204
BAD_REQUEST = 400
UNAUTHORIZED = 401
class ShuffleLine:
def __init__(self, inp_file):
self.file_name = inp_file
# Shuffling with help of list of tuples
def shuffle_read(self):
file_name = self.file_name
with open(file_name, 'r') as f:
data = [(random.random(), line) for line in f]
//Accessing a List
//A list can be accessed by an index, a for/foreach loop, and using LINQ queries. Indexes of a list start from zero. Pass an index in the square brackets to access individual list items, same as array. Use a foreach or for loop to iterate a List<T> collection.
//Example: Accessing List
List<int> numbers = new List<int>() { 1, 2, 5, 7, 8, 10 };
Console.WriteLine(numbers[0]); // prints 1
Console.WriteLine(numbers[1]); // prints 2
Console.WriteLine(numbers[2]); // prints 5
Console.WriteLine(numbers[3]); // prints 7
*** Arrays ***
class MyApp
{
static void Main()
{
// Array declaration
int[] x; // not int x[]
// Array allocation
var arlist1 = new ArrayList();
var arlist2 = new ArrayList()
{
1, "Bill", " ", true, 4.5, null
};
int[] arr = { 100, 200, 300, 400 };
Queue myQ = new Queue();
1. List of anything
You can specify not only custom types. List<int>, List<double>,
List<string> will works as well. If you need to store mixed types -
you need to specify closest base class for all types.
In List<object> can be stored instance of any type.
If you are willing to give away type safety you can use an ArrayList,
which was the only way to use a list of stuff pre generics.
Java Snippets
Converting Strings to int and int to String
String a = String.valueOf(2);
int i = Integer.parseInt(a);
Convert String to Date
java.util.Date = java.text.DateFormat.getDateInstance().parse(date String);
or
SimpleDateFormat format = new SimpleDateFormat( "dd.MM.yyyy" );
Date date = format.parse( myString );
Install pip
Pip (Python Package Installer), official documentation for pip.
Usually Python3 comes with pip preinstalled. If you get an error "pip command not found", use the following command to install pip:
Download get-pip.py, make sure you're saving file to Desktop
In your Command Prompt navigate to Desktop
cd Desktop
THE FOUNDER’S GUIDE:
How to Install and Manage Multiple Python Versions on Windows 10
The expanded tutorial with concise explanations and screenshots
David Littlefield
Follow
Jan 13 · 10 min read
Image by Isabella and Louisa Fischer