├── machine-learning ├── Data-Distribution.py ├── Decision-Tree.py ├── Linear-Regression.py ├── Mean-Median-Mode.py ├── Normal-Data-Distribution.py ├── Percentile.py ├── Scatter -Plot.py ├── Standard-Deviation.py └── data.csv ├── numpy ├── __pycache__ │ └── seaborn.cpython-310.pyc ├── array_Iterating.py ├── array_filter.py ├── array_index.py ├── array_init.py ├── array_joining.py ├── array_reshape.py ├── array_search.py ├── array_shape.py ├── array_slice.py ├── array_sort.py ├── array_split.py ├── binomial_distribution.py ├── copy_view.py ├── data_distribution.py ├── datatypes.py ├── normal_distribution.py ├── numpy_random.py ├── poission_distribution.py ├── random_choice.py ├── random_permutation.py ├── seaborn.py └── uniform_distribution.py └── python ├── __pycache__ └── datetime.cpython-311.pyc ├── class.py ├── contribute.py ├── dictionary.py ├── helloworld.py ├── history.md ├── input.py ├── iterator.py ├── json.py ├── lambda.py ├── list.py ├── module ├── __pycache__ │ └── mymodule.cpython-311.pyc ├── datetime.py ├── main.py └── mymodule.py ├── py contribute.py --repository=git@github.md ├── set.py ├── string.py ├── try..except.py └── tuple.py /machine-learning/Data-Distribution.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | import matplotlib.pyplot as plt 3 | 4 | x = numpy.random.uniform(0.0, 5.0, 250) 5 | 6 | plt.hist(x, 5) 7 | plt.show() -------------------------------------------------------------------------------- /machine-learning/Decision-Tree.py: -------------------------------------------------------------------------------- 1 | #Three lines to make our compiler able to draw: 2 | import sys 3 | import matplotlib 4 | matplotlib.use('Agg') 5 | 6 | import pandas 7 | from sklearn import tree 8 | from sklearn.tree import DecisionTreeClassifier 9 | import matplotlib.pyplot as plt 10 | 11 | df = pandas.read_csv("data.csv") 12 | 13 | d = {'UK': 0, 'USA': 1, 'N': 2} 14 | df['Nationality'] = df['Nationality'].map(d) 15 | d = {'YES': 1, 'NO': 0} 16 | df['Go'] = df['Go'].map(d) 17 | 18 | features = ['Age', 'Experience', 'Rank', 'Nationality'] 19 | 20 | X = df[features] 21 | y = df['Go'] 22 | 23 | dtree = DecisionTreeClassifier() 24 | dtree = dtree.fit(X, y) 25 | 26 | tree.plot_tree(dtree, feature_names=features) 27 | 28 | #Two lines to make our compiler able to draw: 29 | plt.savefig(sys.stdout.buffer) 30 | sys.stdout.flush() 31 | 32 | #NOTE: 33 | #You will see that the Decision Tree gives you different results if you run it enough times, even if you feed it with the same data. 34 | 35 | #That is because the Decision Tree does not give us a 100% certain answer. It is based on the probability of an outcome, and the answer will vary. 36 | -------------------------------------------------------------------------------- /machine-learning/Linear-Regression.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | from scipy import stats 3 | 4 | x = [5,7,8,7,2,17,2,9,4,11,12,9,6] 5 | y = [99,86,87,88,111,86,103,87,94,78,77,85,86] 6 | 7 | slope, intercept, r, p, std_err = stats.linregress(x, y) 8 | 9 | def myfunc(x): 10 | return slope * x + intercept 11 | 12 | mymodel = list(map(myfunc, x)) 13 | 14 | plt.scatter(x, y) 15 | plt.plot(x, mymodel) 16 | plt.show() -------------------------------------------------------------------------------- /machine-learning/Mean-Median-Mode.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | 3 | from scipy import stats 4 | 5 | speed = [99,86,87,88,111,86,103,87,94,78,77,85,86] 6 | 7 | mean = numpy.mean(speed) 8 | 9 | median = numpy.median(speed) 10 | 11 | mode = stats.mode(speed) 12 | 13 | print("mean:", mean) 14 | 15 | print("median:", median) 16 | 17 | print("mode:", mode) -------------------------------------------------------------------------------- /machine-learning/Normal-Data-Distribution.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | import matplotlib.pyplot as plt 3 | 4 | x = numpy.random.normal(5.0, 1.0, 100000) 5 | 6 | plt.hist(x, 100) 7 | plt.show() -------------------------------------------------------------------------------- /machine-learning/Percentile.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | 3 | ages = [5,31,43,48,50,41,7,11,15,39,80,82,32,2,8,6,25,36,27,61,31] 4 | 5 | x = numpy.percentile(ages, 75) 6 | 7 | print(x) -------------------------------------------------------------------------------- /machine-learning/Scatter -Plot.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | 3 | x = [5,7,8,7,2,17,2,9,4,11,12,9,6] 4 | y = [99,86,87,88,111,86,103,87,94,78,77,85,86] 5 | 6 | plt.scatter(x, y) 7 | plt.show() -------------------------------------------------------------------------------- /machine-learning/Standard-Deviation.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | 3 | speed = [32,111,138,28,59,77,97] 4 | 5 | x = numpy.var(speed) 6 | 7 | y = numpy.std(speed) 8 | 9 | print("var:", x) 10 | 11 | print("std:", y) -------------------------------------------------------------------------------- /machine-learning/data.csv: -------------------------------------------------------------------------------- 1 | Age,Experience,Rank,Nationality,Go 2 | 36,10,9,UK,NO 3 | 42,12,4,USA,NO 4 | 23,4,6,N,NO 5 | 52,4,4,USA,NO 6 | 43,21,8,USA,YES 7 | 44,14,5,UK,NO 8 | 66,3,7,N,YES 9 | 35,14,9,UK,YES 10 | 52,13,7,N,YES 11 | 35,5,9,N,YES 12 | 24,3,5,USA,NO 13 | 18,3,7,UK,YES 14 | 45,9,9,UK,YES 15 | -------------------------------------------------------------------------------- /numpy/__pycache__/seaborn.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Topten1004/Python-Learning/719a4cd1f7b33a1e7a6fdf2fdcb8fa87220c21a0/numpy/__pycache__/seaborn.cpython-310.pyc -------------------------------------------------------------------------------- /numpy/array_Iterating.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | arr = np.array([[1,2,3], [4,5,6]]) 4 | 5 | # iterate on the elements of the following 2-D array: 6 | for x in arr: 7 | print(x) 8 | 9 | # iterate on each scalar element of the 2-D array 10 | arr = np.array([[1,2,3], [4,5,6]]) 11 | for x in arr: 12 | for y in x: 13 | print(y) 14 | 15 | # iterate on the elements of the following 3-D array 16 | 17 | arr = np.array([[[1,2,3], [4,5,6],[7,8,9], [10,11,12]]]) 18 | 19 | for x in arr: 20 | print(x) 21 | 22 | # iterate through teh following 3-D array: 23 | 24 | arr = np.array([[[1,2], [3,4], [5,6], [7,8]]]) 25 | 26 | for x in np.nditer(arr): 27 | print(x) 28 | 29 | arr = np.array([1, 2, 3]) 30 | 31 | for x in np.nditer(arr, flags=['buffered'], op_dtypes=['S']): 32 | print(x) 33 | 34 | arr = np.array([1,2,3]) 35 | for idx, x in np.ndenumerate(arr): 36 | print(idx,x) 37 | -------------------------------------------------------------------------------- /numpy/array_filter.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | arr = np.array([1,2,5,4,3]) 4 | 5 | x = [True, False, False,True, False] 6 | 7 | newarr = arr[x] 8 | 9 | print(newarr) 10 | 11 | # Create an empty list 12 | filter_arr = [] 13 | 14 | # go through each element in arr 15 | for element in arr: 16 | # if the element is higher than 42, set the value to True, otherwise False: 17 | if element > 42: 18 | filter_arr.append(True) 19 | else: 20 | filter_arr.append(False) 21 | 22 | newarr = arr[filter_arr] 23 | 24 | print(filter_arr) 25 | print(newarr) -------------------------------------------------------------------------------- /numpy/array_index.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | arr = np.array([1, 2, 3, 4]) 4 | 5 | print(arr[0]) 6 | 7 | 8 | arr = np.array([[1,2,3,4],[6,7,8,9]]) 9 | 10 | print(arr[1,1]) 11 | 12 | arr = np.array([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]]) 13 | 14 | print(arr[0, 1, 2]) 15 | 16 | arr = np.array([[1,2,3,4,5], [6,7,8,9,10]]) 17 | 18 | print('Last element from 2nd dim: ', arr[1, -1]) -------------------------------------------------------------------------------- /numpy/array_init.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | arr = np.array([1, 2, 3, 4]) 3 | 4 | print(arr) 5 | 6 | print(type(arr)) 7 | 8 | 9 | arr = np.array((1,2,3,4)) 10 | 11 | print(arr) 12 | 13 | print(type(arr)) 14 | 15 | arr = np.array([[1,2,3,4],[1,2,3,4]]) 16 | 17 | print(arr) -------------------------------------------------------------------------------- /numpy/array_joining.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | arr1 = np.array([1,2,3]) 4 | 5 | arr2 = np.array([4,5,6]) 6 | 7 | arr = np.concatenate([arr1, arr2]) 8 | 9 | print(arr) 10 | 11 | # Join two 2-D arrays along rows (axis = 1) 12 | 13 | arr1 = np.array([[1,2], [3,4], [5,6]]) 14 | arr2 = np.array([[7,8], [9,10], [11,12]]) 15 | 16 | arr = np.concatenate((arr1, arr2), axis = 0) 17 | 18 | print(arr) 19 | 20 | a = np.array([[1,2,3,4],[5,6,7,8], [9,10,11,12],[13,14,15,16]]) 21 | b = np.array([[17,18,19,20],[21,22,23,24],[25,26,27,28],[29,30,31,32]]) 22 | c = np.concatenate((a, b), axis=1) 23 | print(a) 24 | print(b) 25 | print(c) 26 | # Joining Arrays using Stack functions 27 | arr = np.stack((a,b), axis=0) 28 | print(arr) 29 | 30 | # Stacking Along Rows 31 | arr = np.hstack((arr1, arr2)) 32 | print(arr) 33 | 34 | # Stacking Along Columns 35 | arr = np.vstack((arr1, arr2)) 36 | print(arr) 37 | 38 | # Stacking Along Height(Depth) 39 | arr = np.dstack((arr1, arr2)) 40 | print(arr) -------------------------------------------------------------------------------- /numpy/array_reshape.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | arr = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) 4 | 5 | newarr = arr.reshape(4, 3) 6 | 7 | print(newarr) 8 | 9 | # Convert the following 1-D array with 12 elements into a 3-D array 10 | newarr = arr.reshape(2, 3, 2) 11 | 12 | print(newarr) 13 | 14 | arr = np.array([1, 2, 3, 4, 5, 6, 7, 8]) 15 | 16 | newarr = arr.reshape(2, 2, -1) 17 | 18 | print(newarr) 19 | 20 | # convert the array into a 1D array: 21 | arr = np.array([[1, 2, 3], [4, 5, 6]]) 22 | 23 | newarr = arr.reshape(-1) 24 | 25 | print(newarr) -------------------------------------------------------------------------------- /numpy/array_search.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | arr = np.array([1,2,3,4,4,5,6]) 4 | 5 | x = np.where(arr == 4) 6 | 7 | print(x) 8 | 9 | arr = np.array([1,2,3,4,5,6,7,8]) 10 | 11 | x = np.where(arr %2 == 0) 12 | 13 | print(x) 14 | 15 | x = np.where( arr % 2 == 1) 16 | 17 | print(x) 18 | 19 | arr = np.array([6, 7, 8, 9]) 20 | 21 | x = np.searchsorted(arr, 7) 22 | 23 | print(x) 24 | 25 | arr = np.array([6, 7, 8, 9]) 26 | 27 | x = np.searchsorted(arr, 7, side='right') 28 | 29 | print(x) 30 | 31 | arr = np.array([1, 3, 5, 7]) 32 | 33 | x = np.searchsorted(arr, [2, 4, 6]) 34 | 35 | # 1 2 3 5 7 [1] 36 | # 1 3 4 5 7 [2] 37 | # 1 3 5 6 7 [3] 38 | print(x) 39 | 40 | -------------------------------------------------------------------------------- /numpy/array_shape.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | arr = np.array([[1,2,3,4], [5,6,7,8]]) 4 | 5 | print(arr.shape) 6 | 7 | # create an array with 5 dimensions using ndmin using a vector with values 1,2,3,4 and verify that last dimensions has value 4 8 | arr = np.array([[1,2,3,4], [5,6,7,8]]) 9 | 10 | print(arr.shape) 11 | 12 | 13 | # create an array with 5 dimensions 14 | arr = np.array([1,2,3,4], ndmin=4) 15 | 16 | print(arr) 17 | print('shape of array : ', arr.shape) -------------------------------------------------------------------------------- /numpy/array_slice.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | arr = np.array([1, 2, 3, 4, 5, 6, 7, 8]) 4 | 5 | print(arr[1:5]) 6 | 7 | arr = np.array([1, 2, 3, 4, 5, 6, 7]) 8 | 9 | print(arr[:4]) 10 | 11 | print(arr[4:]) 12 | 13 | #negative slice 14 | print(arr[-3:-1]) 15 | 16 | # print items by interval 3 17 | print(arr[1:6:3]) 18 | 19 | # return every items by interval 20 | print(arr[::2]) 21 | 22 | arr = np.array([[1,2,3,4,5],[6,7,8,9,10]]) 23 | 24 | # multiple dimension array 25 | print(arr[1, 1:4]) 26 | 27 | # return index both arrays 28 | print(arr[0:2, 3]) 29 | 30 | # from both elements, slice index 1 to index 4 (not included), this will return a 2-D array 31 | arr = np.array([[1,2,3,4,5],[6,7,8,9,10]]) 32 | 33 | # from both elements, slice index 1 to index 4 (not included), this will return a 2-D array 34 | print(arr[0:2, 1:4]) 35 | 36 | -------------------------------------------------------------------------------- /numpy/array_sort.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | arr = np.array([3, 2, 0, 1]) 4 | 5 | # sort array 6 | print(np.sort(arr)) 7 | 8 | arr = np.array(['banana','cherry','orange','apple']) 9 | 10 | # sort text 11 | print(np.sort(arr)) 12 | 13 | arr = np.array([[3,2,4], [5,9,8]]) 14 | 15 | #sort 2-D array 16 | print(np.sort(arr)) 17 | -------------------------------------------------------------------------------- /numpy/array_split.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | arr = np.array([1,2,3,4,5,6,7,8]) 4 | 5 | newarr = np.array_split(arr, 4) 6 | 7 | print(newarr) 8 | 9 | newarr = np.array_split(arr, 4) 10 | 11 | print(newarr[0]) 12 | 13 | print(newarr[1]) 14 | 15 | print(newarr[2]) 16 | 17 | arr = np.array([[1,2],[3,4],[5,6],[7,8],[9,10],[11,12]]) 18 | 19 | newarr = np.array_split(arr, 3) 20 | 21 | print(newarr) 22 | 23 | # Split the 2-D array into three 2-D arrays 24 | 25 | arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15], [16, 17, 18]]) 26 | 27 | newarr = np.array_split(arr, 3) 28 | 29 | print(newarr) 30 | 31 | arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15], [16, 17, 18]]) 32 | 33 | newarr = np.array_split(arr, 3, axis=1) 34 | 35 | print(newarr) 36 | 37 | arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15], [16, 17, 18]]) 38 | 39 | newarr = np.hsplit(arr, 3) 40 | 41 | print(newarr) -------------------------------------------------------------------------------- /numpy/binomial_distribution.py: -------------------------------------------------------------------------------- 1 | from numpy import random 2 | 3 | x = random.binomial(10, 0.5, 100) 4 | 5 | print(x) -------------------------------------------------------------------------------- /numpy/copy_view.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | arr = np.array([1, 2, 3, 4, 5]) 4 | x = arr.copy() 5 | arr[0] = 12 6 | 7 | print(arr) 8 | print(x) 9 | 10 | arr = np.array([1, 2, 3, 4, 5]) 11 | x = arr.view() 12 | 13 | arr[0] = 100 14 | 15 | print(arr) 16 | print(x) 17 | 18 | # check with base 19 | 20 | arr = np.array([1, 2, 3, 4, 5]) 21 | 22 | x = arr.copy() 23 | y = arr.view() 24 | 25 | # copy return none 26 | print(x.base) 27 | # view returns original array 28 | print(y.base) 29 | -------------------------------------------------------------------------------- /numpy/data_distribution.py: -------------------------------------------------------------------------------- 1 | from numpy import random 2 | 3 | x = random.choice([3, 5, 7, 9], p=[0.1, 0.3, 0.6, 0.0], size=(100)) 4 | 5 | print(x) -------------------------------------------------------------------------------- /numpy/datatypes.py: -------------------------------------------------------------------------------- 1 | # i - integer 2 | # b - boolean 3 | # u - unsigned integer 4 | # f - float 5 | # c - complex float 6 | # m - timedelta 7 | # M - datetime 8 | # O - object 9 | # S - string 10 | # U - unicode string 11 | # V - fixed chunk of memory for other type ( void ) 12 | 13 | import numpy as np 14 | 15 | arr = np.array([1, 2, 3, 4, 5]) 16 | 17 | print(arr.dtype) 18 | 19 | stringArr = np.array(['apple', 'banana', 'cherry']) 20 | 21 | print(stringArr.dtype) 22 | 23 | arr = np.array([1,2,3,4], dtype='S') 24 | 25 | print(arr) 26 | print(arr.dtype) 27 | 28 | # set datatype 29 | arr = np.array([1,2,3,4], dtype='i4') 30 | 31 | print(arr) 32 | print(arr.dtype) 33 | 34 | # convert datatype float to int 35 | arr = np.array([1.2, 2.3, 3.5, 4.5]) 36 | 37 | newarr = arr.astype('i') 38 | 39 | print(newarr) 40 | 41 | print(newarr.dtype) 42 | 43 | # convert float type to int type 44 | arr = np.array([1.1, 2.1, 5.1]) 45 | 46 | newarr = arr.astype(int) 47 | 48 | print(newarr) 49 | print(newarr.dtype) 50 | 51 | # convert data type from integer to boolean 52 | arr = np.array([1, 0, 3]) 53 | 54 | newarr = arr.astype(bool) 55 | 56 | print(newarr) 57 | print(newarr.dtype) 58 | -------------------------------------------------------------------------------- /numpy/normal_distribution.py: -------------------------------------------------------------------------------- 1 | from numpy import random 2 | 3 | x = random.normal(100, 14, 5) 4 | 5 | print(x) -------------------------------------------------------------------------------- /numpy/numpy_random.py: -------------------------------------------------------------------------------- 1 | from numpy import random 2 | 3 | x = random.randint(100) 4 | 5 | print(x) 6 | 7 | x = random.rand() 8 | 9 | print(x) 10 | 11 | x=random.randint(100, size=(5)) 12 | 13 | print(x) 14 | 15 | x = random.randint(100, size=(3, 5)) 16 | 17 | print(x) 18 | 19 | x = random.rand(5) 20 | 21 | print(x) -------------------------------------------------------------------------------- /numpy/poission_distribution.py: -------------------------------------------------------------------------------- 1 | from numpy import random 2 | 3 | x = random.poisson(lam=3, size =10) 4 | 5 | print(x) -------------------------------------------------------------------------------- /numpy/random_choice.py: -------------------------------------------------------------------------------- 1 | from numpy import random 2 | 3 | x = random.choice([3,5,7,9,11], size=(3,5)) 4 | 5 | print(x) -------------------------------------------------------------------------------- /numpy/random_permutation.py: -------------------------------------------------------------------------------- 1 | from numpy import random 2 | import numpy as np 3 | 4 | arr = np.array([1, 2, 3, 4, 5]) 5 | 6 | random.shuffle(arr) 7 | 8 | print(arr) 9 | 10 | arr = np.array([1, 2, 3, 4, 5]) 11 | 12 | print(random.permutation(arr)) -------------------------------------------------------------------------------- /numpy/seaborn.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | import seaborn as sns 3 | 4 | sns.distplot([0, 1, 2, 3, 4, 5]) 5 | 6 | plt.show() -------------------------------------------------------------------------------- /numpy/uniform_distribution.py: -------------------------------------------------------------------------------- 1 | from numpy import random 2 | import matplotlib.pyplot as plt 3 | import seaborn as sns 4 | 5 | sns.distplot(random.uniform(size=1000), hist=False) 6 | 7 | plt.show() -------------------------------------------------------------------------------- /python/__pycache__/datetime.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Topten1004/Python-Learning/719a4cd1f7b33a1e7a6fdf2fdcb8fa87220c21a0/python/__pycache__/datetime.cpython-311.pyc -------------------------------------------------------------------------------- /python/class.py: -------------------------------------------------------------------------------- 1 | class Person: 2 | def __init__(self, name, age): 3 | self.name = name 4 | self.age = age 5 | 6 | def __str__(self): 7 | return f"{self.name} ({self.age})" 8 | 9 | p1 = Person("John", 34) 10 | 11 | print(p1) 12 | 13 | class Student(Person): 14 | def __init__(self, fname, lname): 15 | super().__init__(fname, lname) 16 | self.graduationyear = 2019 17 | 18 | 19 | p = Student("David","Riley") 20 | 21 | print(p) -------------------------------------------------------------------------------- /python/contribute.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import argparse 3 | import errno 4 | import os 5 | import stat 6 | import shutil 7 | from datetime import datetime 8 | from datetime import timedelta 9 | from random import randint 10 | from subprocess import Popen 11 | import sys 12 | 13 | # NUM = 366 14 | 15 | 16 | def remove_readonly(func, path, excinfo): 17 | os.chmod(path, stat.S_IWRITE) 18 | func(path) 19 | 20 | 21 | def main(def_args=sys.argv[1:]): 22 | args = arguments(def_args) 23 | curr_date = datetime.now() 24 | directory = 'repository-' + curr_date.strftime('%Y-%m-%d-%H-%M-%S') 25 | repository = args.repository 26 | user_name = args.user_name 27 | user_email = args.user_email 28 | if repository is not None: 29 | start = repository.rfind('/') + 1 30 | end = repository.rfind('.') 31 | directory = repository[start:end] 32 | no_weekends = args.no_weekends 33 | frequency = args.frequency 34 | # if os.path.exists(directory): 35 | # shutil.rmtree(directory, onerror=remove_readonly) 36 | # os.mkdir(directory) 37 | # os.chdir(directory) 38 | # run(['git', 'init']) 39 | 40 | if user_name is not None: 41 | run(['git', 'config', 'user.name', user_name]) 42 | 43 | if user_email is not None: 44 | run(['git', 'config', 'user.email', user_email]) 45 | 46 | if args.start_date is None: 47 | NUM = args.days_ago 48 | start_date = curr_date.replace(hour=20, minute=0) - timedelta(NUM) 49 | else: 50 | start_date = datetime.strptime(args.start_date, "%Y/%m/%d, %H:%M:%S") 51 | NUM = (curr_date.replace(hour=20, minute=0) - start_date).days 52 | for day in (start_date + timedelta(n) for n in range(NUM)): 53 | if (not no_weekends or day.weekday() < 5) \ 54 | and randint(0, 100) < frequency: 55 | for commit_time in (day + timedelta(minutes=m) 56 | for m in range(contributions_per_day(args))): 57 | contribute(commit_time) 58 | 59 | if repository is not None: 60 | run(['git', 'remote', 'add', 'origin', repository]) 61 | run(['git', 'branch', '-M', 'main']) 62 | run(['git', 'push', '-u', 'origin', 'main']) 63 | 64 | print('\nRepository generation ' + 65 | '\x1b[6;30;42mcompleted successfully\x1b[0m!') 66 | 67 | 68 | def contribute(date): 69 | with open(os.path.join(os.getcwd(), 'history.md'), 'a') as file: 70 | file.write(message(date) + '\n\n') 71 | run(['git', 'add', '.']) 72 | run(['git', 'commit', '-m', '"%s"' % message(date), 73 | '--date', date.strftime('"%Y-%m-%d %H:%M:%S"')]) 74 | 75 | 76 | def run(commands): 77 | Popen(commands).wait() 78 | 79 | 80 | def message(date): 81 | return date.strftime('Contribution: %Y-%m-%d %H:%M') 82 | 83 | 84 | def contributions_per_day(args): 85 | max_c = args.max_commits 86 | if max_c > 20: 87 | max_c = 20 88 | if max_c < 1: 89 | max_c = 1 90 | return randint(1, max_c) 91 | 92 | 93 | def arguments(argsval): 94 | parser = argparse.ArgumentParser() 95 | parser.add_argument('-nw', '--no_weekends', 96 | required=False, action='store_true', default=False, 97 | help="""do not commit on weekends""") 98 | parser.add_argument('-mc', '--max_commits', type=int, default=7, 99 | required=False, help="""Defines the maximum amount of 100 | commits a day the script can make. Accepts a number 101 | from 1 to 20. If N is specified the script commits 102 | from 1 to N times a day. The exact number of commits 103 | is defined randomly for each day. The default value 104 | is 10.""") 105 | parser.add_argument('-fr', '--frequency', type=int, default=80, 106 | required=False, help="""Percentage of days when the 107 | script performs commits. If N is specified, the script 108 | will commit N%% of days in a year. The default value 109 | is 80.""") 110 | parser.add_argument('-r', '--repository', type=str, required=False, 111 | help="""A link on an empty non-initialized remote git 112 | repository. If specified, the script pushes the changes 113 | to the repository. The link is accepted in SSH or HTTPS 114 | format. For example: git@github.com:user/repo.git or 115 | https://github.com/user/repo.git""") 116 | parser.add_argument('-un', '--user_name', type=str, required=False, default="TopTen1004", 117 | help="""Overrides user.name git config. 118 | If not specified, the global config is used.""") 119 | parser.add_argument('-ue', '--user_email', type=str, required=False, default="arthur.chen330@gmail.com", 120 | help="""Overrides user.email git config. 121 | If not specified, the global config is used.""") 122 | parser.add_argument('-da', '--days_ago', type=int, required=False, default=25, 123 | help="""Show them if you want to contribute a few days in advance.""") 124 | parser.add_argument('-sd', '--start_date', type=str, required=False, 125 | help="""Start Date.""") 126 | return parser.parse_args(argsval) 127 | 128 | 129 | if __name__ == "__main__": 130 | main() 131 | -------------------------------------------------------------------------------- /python/dictionary.py: -------------------------------------------------------------------------------- 1 | thisdict = { 2 | "brand": "Ford", 3 | "model": "Mustang", 4 | "year": 1964 5 | } 6 | print(thisdict["brand"]) 7 | 8 | 9 | thisdict = { 10 | "brand": "Ford", 11 | "model": "Mustang", 12 | "year": 1964, 13 | "year": 2020 14 | } 15 | print(thisdict) 16 | 17 | print(len(thisdict)) 18 | 19 | x = thisdict.get("model") 20 | 21 | print(x) 22 | 23 | x = thisdict.values() 24 | 25 | y = thisdict.keys() 26 | 27 | print(x) 28 | 29 | print(y) 30 | 31 | x = thisdict.items() 32 | 33 | print(x) 34 | 35 | thisdict.update({"color": "red"}) 36 | 37 | print(x) 38 | 39 | child1 = { 40 | "name" : "Emil", 41 | "year" : 2004 42 | } 43 | child2 = { 44 | "name" : "Tobias", 45 | "year" : 2007 46 | } 47 | child3 = { 48 | "name" : "Linus", 49 | "year" : 2011 50 | } 51 | 52 | myfamily = { 53 | "child1" : child1, 54 | "child2" : child2, 55 | "child3" : child3 56 | } -------------------------------------------------------------------------------- /python/helloworld.py: -------------------------------------------------------------------------------- 1 | print("Hello, world") 2 | if 5 > 2: 3 | print("Five is larger than two") 4 | print("Error") -------------------------------------------------------------------------------- /python/input.py: -------------------------------------------------------------------------------- 1 | username = input("Enter username:") 2 | print("Username is: " + username) -------------------------------------------------------------------------------- /python/iterator.py: -------------------------------------------------------------------------------- 1 | mytuple = ("apple", "banana", "cherry") 2 | myit = iter(mytuple) 3 | 4 | print(next(myit)) 5 | print(next(myit)) 6 | print(next(myit)) 7 | 8 | class MyNumbers: 9 | def __iter__(self): 10 | self.a = 1 11 | return self 12 | 13 | def __next__(self): 14 | x = self.a 15 | self.a += 1 16 | return x 17 | 18 | myclass = MyNumbers() 19 | myiter = iter(myclass) 20 | 21 | print(next(myiter)) 22 | print(next(myiter)) 23 | print(next(myiter)) 24 | print(next(myiter)) 25 | print(next(myiter)) -------------------------------------------------------------------------------- /python/json.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | # some JSON: 4 | x = '{ "name":"John", "age":30, "city":"New York"}' 5 | 6 | # parse x: 7 | y = json.loads(x) 8 | 9 | # the result is a Python dictionary: 10 | print(y["age"]) 11 | 12 | print(json.dumps({"name": "John", "age": 30})) 13 | print(json.dumps(["apple", "bananas"])) 14 | print(json.dumps(("apple", "bananas"))) 15 | print(json.dumps("hello")) 16 | print(json.dumps(42)) 17 | print(json.dumps(31.76)) 18 | print(json.dumps(True)) 19 | print(json.dumps(False)) 20 | print(json.dumps(None)) -------------------------------------------------------------------------------- /python/lambda.py: -------------------------------------------------------------------------------- 1 | x = lambda a, b, c : a + b + c 2 | print(x(5, 6, 2)) -------------------------------------------------------------------------------- /python/list.py: -------------------------------------------------------------------------------- 1 | mylist = ["apple", "banana", "cherry"] 2 | 3 | print(type(mylist)) 4 | 5 | print(len(mylist)) 6 | 7 | thislist = list(("Real Madrid", "FC barocellona", "PSG", "AC Milan", "Manchester United")) 8 | 9 | print(thislist) 10 | 11 | # print last item of thislist 12 | print(thislist[-1]) 13 | 14 | print(thislist[2:5]) 15 | 16 | print(thislist[:4]) 17 | 18 | print(thislist[2:]) 19 | 20 | print(thislist[-4:-1]) 21 | 22 | if "PSG" in thislist: 23 | print("Yes") 24 | 25 | thislist.insert(len(thislist), "Chelsea") 26 | 27 | print(thislist) 28 | 29 | thislist[1] = "Inter Milan" 30 | 31 | thislist[2:4] = ["Bayern Munchen", "Borussia Dortmund"] 32 | 33 | thislist.pop(1) 34 | 35 | thislist.remove("Chelsea") 36 | 37 | for x in thislist: 38 | print(x) 39 | 40 | for i in range(len(thislist)): 41 | print(thislist[i]) 42 | 43 | [print(x) for x in thislist] 44 | 45 | thislist.sort() 46 | 47 | thislist.reverse() 48 | 49 | newlist = thislist.copy() 50 | 51 | otherlist = list(newlist) 52 | 53 | print(thislist) -------------------------------------------------------------------------------- /python/module/__pycache__/mymodule.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Topten1004/Python-Learning/719a4cd1f7b33a1e7a6fdf2fdcb8fa87220c21a0/python/module/__pycache__/mymodule.cpython-311.pyc -------------------------------------------------------------------------------- /python/module/datetime.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | 3 | x = datetime.datetime.now() 4 | 5 | print(x.year) 6 | print(x.strftime("%A")) 7 | 8 | x = datetime.datetime(2020, 5, 17) 9 | 10 | print(x) -------------------------------------------------------------------------------- /python/module/main.py: -------------------------------------------------------------------------------- 1 | import mymodule as mm 2 | 3 | import platform 4 | 5 | mm.greeting("David") 6 | 7 | x = mm.person1["age"] 8 | 9 | print(x) 10 | 11 | x = platform.system() 12 | print(x) -------------------------------------------------------------------------------- /python/module/mymodule.py: -------------------------------------------------------------------------------- 1 | def greeting(name): 2 | print("Hello, " + name) 3 | 4 | person1 = { 5 | "name" : "David", 6 | "age" : 32, 7 | } -------------------------------------------------------------------------------- /python/py contribute.py --repository=git@github.md: -------------------------------------------------------------------------------- 1 | py contribute.py --repository=git@github.com:TopTen1004/Python-Learning.git -sd="2013/02/01, 18:54:33" 95 2 | -------------------------------------------------------------------------------- /python/set.py: -------------------------------------------------------------------------------- 1 | thisset = {"apple", "banana", "cherry"} 2 | print(thisset) 3 | 4 | 5 | set1 = {"apple", "banana", "cherry"} 6 | set2 = {1, 5, 7, 9, 3} 7 | set3 = {True, False, False} 8 | 9 | thisset = {"apple", "banana", "cherry"} 10 | tropical = {"pineapple", "mango", "papaya"} 11 | 12 | thisset.update(tropical) 13 | 14 | print(thisset) 15 | 16 | thisset = {"apple", "banana", "cherry"} 17 | mylist = ["kiwi", "orange"] 18 | 19 | thisset.update(mylist) 20 | 21 | print(thisset) 22 | 23 | thisset = {"apple", "banana", "cherry"} 24 | 25 | for x in thisset: 26 | print(x) 27 | 28 | set1 = {"apple", "banana", "cherry"} 29 | set2 = {1,2,3} 30 | 31 | set3 = set1.union(set2) 32 | 33 | print(set3) 34 | 35 | -------------------------------------------------------------------------------- /python/string.py: -------------------------------------------------------------------------------- 1 | a="hello" 2 | print(a) 3 | print(a[1]) 4 | txt = "The best things in life are free!" 5 | print("free" in txt) 6 | 7 | if "free" in txt: 8 | print("Yes, 'free' is present.") 9 | 10 | txt = "The best things in life are free!" 11 | print("expensive" not in txt) 12 | 13 | print(txt.upper()) 14 | 15 | txt = "The best football club is {} and footballer is {}" 16 | print(txt.format("Real Madrid", "Reao")) 17 | 18 | a = 200 19 | b = 50 20 | 21 | if b > a : 22 | print("b is greater than a") 23 | else : 24 | print("b is greater than a") 25 | -------------------------------------------------------------------------------- /python/try..except.py: -------------------------------------------------------------------------------- 1 | try: 2 | f = open("demofile.txt") 3 | try: 4 | f.write("Lorum Ipsum") 5 | except: 6 | print("Something went wrong when writing to the file") 7 | finally: 8 | f.close() 9 | except: 10 | print("Something went wrong when opening the file") 11 | 12 | x = "hello" 13 | 14 | if not type(x) is int: 15 | raise TypeError("Only integers are allowed") -------------------------------------------------------------------------------- /python/tuple.py: -------------------------------------------------------------------------------- 1 | x = ("apple", "banana", "cherry") 2 | y = list(x) 3 | y[1] = "kiwi" 4 | x = tuple(y) 5 | 6 | print(x) 7 | 8 | (one, two, three) = x 9 | print(one) 10 | print(two) 11 | print(three) 12 | 13 | thistuple = ("apple", "banana", "cherry") 14 | for x in thistuple: 15 | print(x) 16 | 17 | for i in range(len(thistuple)): 18 | print(thistuple[i]) 19 | 20 | i = 0; 21 | while i < len(thistuple) - 1: 22 | print(thistuple[i]) 23 | i += 1 24 | 25 | fruits = ("apple", "banana", "cherry") 26 | mytuple = fruits * 2 27 | 28 | print(mytuple) 29 | --------------------------------------------------------------------------------