blob_id
stringlengths
40
40
repo_name
stringlengths
5
127
path
stringlengths
2
523
length_bytes
int64
22
545k
score
float64
3.5
5.34
int_score
int64
4
5
text
stringlengths
22
545k
4c278680c7c2edd60a3435a9aa424a0a1ac1de6d
diksha16017/fcs_assignment1
/assignment/CipherToPlain.py
1,523
4.28125
4
cipher1 = "slnpzshabylzohssthrluvshdylzwljapunhulzahispzotluavmylspnpvuvywyvopipapunaolmylllelyjpzlaolylvmvyh" cipher2 = "iypknpunaolmyllkvtvmzwlljovyvmaolwylzzvyaolypnoavmaolwlvwslwlhjlhisfavhzzltislhukavwlapapvuaolnvcl" cipher3 = "yutluamvyhylkylzzvmnyplchujlz" alphabets_frequency = dict() def find_frequency(text1...
c40552d1e0f9b98e303fb49a12a29350265a364e
atsuki12345/git_tutorial
/practice1_facebook.py
806
3.84375
4
''' Q1.Facebook 整数で構成される降順ソート済みの配列intArrが与えられるので、各要素を2乗し降順に並べ変えた配列を返す、sortedSquaredという関数を作成してください。 input [-6, -3, -1, 2, 4, 5] output [1, 4, 9, 16, 25, 36] input [-5, -4, -2, 0, 1] output [0, 1, 4, 16, 25] Hint: 時間計算量:O(n) ''' def sortedSquared(num_list): squated_list = [] for i in num_list: squated_li...
32d4d70033849705b9fad55f7ae70d107173e1cc
afd57/python_useful
/XmlTools/xml_parser.py
570
3.59375
4
#!/usr/bin/python37 import os import sys import xml.etree.ElementTree as ET def xml_parser(xml_path='country_info.xml'): xml_path = 'country_info.xml' tree = ET.parse(xml_path) root = tree.getroot() print(root) def rec_xml_parser(root,child_name,attr_name): for child in root.findall(child_name)...
5b6f5dbb983873f68c90446da96a1cd31795f269
coderdojo-malahide/python-samples
/10_evil_name_1.py
461
3.78125
4
import random titles = ['sir', 'lady', 'dame', 'duke', 'master', 'countess'] first_names = ['slime', 'grit', 'egg', 'fire', 'bone', 'worm'] last_names = ['skull', 'heart', 'hammer', 'maggot', 'snake'] random.shuffle(titles) random.shuffle(first_names) random.shuffle(last_names) my_title = titles[0] my_first_name = f...
5d76cf15fe40d86ed3e6f3f55106b98d87517f6b
cheddalu/look_chuut
/hash_pass_len.py
217
3.578125
4
usr_name = input('What is your username? ') password = (input('Enter in a password: ')) hash_len = len(password) hash_pass = '*' * hash_len print(f'Hi {usr_name} your password {hash_pass} is {hash_len} letters long')
a117b31a7bbe0432da6638f29618955f1e2db08c
cheddalu/look_chuut
/current_age.py
189
4.09375
4
from datetime import datetime birth_year = int(input('What year were you born? ')) current_year = datetime.now().year age = current_year - birth_year print(f'Today you are {age} years old')
db2886f8c983526da4ecfcc12f77da209000a5a9
arunbalajitsr/incubyte_final
/final.py
2,727
3.5625
4
import pandas as pd import sqlite3 as sqlite df = pd.DataFrame() def readsourcefile(): try: df = pd.read_csv("source.txt", sep='|') df = df.iloc[:, 2:] df['DOB'] = pd.to_datetime(df['DOB'], format='%d%m%Y') df['Open_Date'] = pd.to_datetime(df['Open_Date'], format='%Y%m%...
a7dcee34caa62151243132c21b02c52da8d5fcbf
kobe-mop/python
/py_test_code/test/simpleStudy/test_007.py
306
4.0625
4
''' Created on 2016年8月16日 @author: shengxiz ''' #7 DocString# def printMax(x,y): '''Prints the maximum of two numbers. The two values must be integers.''' if x>y: print(x,'is maximum') else: print(y,'is maximum') printMax(3,5) print (printMax.__doc__)
90684cc4cf08e5e96b4abb0e91a754fb9ecc8fc7
kobe-mop/python
/py_usually/src/test/二分法查找.py
535
3.578125
4
''' Created on 2016年11月4日 二分法查找列表中的值,并返回索引值 @author: shengxiz ''' def Binary_search(lst,val): low = 0 high = len(lst)-1 while low<=high: mid = (low+high)//2 if lst[mid]<val: low = mid+1 elif lst[mid]>val: high = mid-1 else: ...
cfa68bffd204bd4b8b0120d751448c9ae5fd5764
kobe-mop/python
/py_test_code/test/simpleStudy/test_016.py
778
4.03125
4
''' Created on 2016年8月16日 @author: shengxiz ''' #16 类和对象的变量 class Person: '''Represents a person.''' population = 0 def __init__(self,name): '''Initializes the person's data.''' self.name=name print('Initalizing %s'%self.name) Person.population+=1 def _...
e69f108f87a3660df2c605f178662b2082ad3124
kobe-mop/python
/py_usually/src/test/合并两个有序列表.py
510
3.953125
4
''' Created on 2016年11月4日 合并两个有序列表,采用递归的方法 @author: shengxiz ''' def Merge_sorted_list(L1,L2,tmp): if len(L1)==0 or len(L2)==0: tmp.extend(L1) tmp.extend(L2) return tmp else: if L1[0]<L2[0]: tmp.append(L1[0]) del L1[0] else: ...
b98308077439e5d3dbbc94a71ba97d79edd0c8a5
kobe-mop/python
/py_test_code/test/simpleStudy/test_017.py
1,175
4.0625
4
''' Created on 2016年8月16日 @author: shengxiz ''' #17 继承 class SchoolMember: '''Represent any school member.''' def __init__(self,name,age): self.name = name self.age = age print('Initialized SchoolMember:%s'%self.name) def tell(self): '''Tell my details.''' ...
c6c87872ba6b39b97355e38743d8df359deca7fe
fly904021125/PythonFirstDemo
/demo/py5_7_180326.py
652
3.953125
4
# coding=utf-8 from fractions import Fraction a = Fraction(1, 2) print(a) b = Fraction('1.2') print(b) print(0.1 + 0.1 + 0.1 - 0.3) # 分数可保持精度计算 print(Fraction('0.1') + Fraction('0.1') + Fraction('0.1') - Fraction('0.3')) # 浮点转换为分数元组 print(2.5.as_integer_ratio()) f = 2.5 print(Fraction(*f.as_integer_ratio())) # 分数混合类型运...
47ba1bb568f524fadac3abb8f80e8f3acd1ab7c7
b93901190/PEI_Python
/ch17/changeMaking.py
238
3.859375
4
def changeMaking(cents): COINS = [100, 50, 25, 10, 5, 1] numCoins = 0 for coin in COINS: if cents >= coin: numCoins += cents // coin cents %= coin return numCoins print(changeMaking(20))
da4c774436ebc59c71222db0507cab7ab69df740
b93901190/PEI_Python
/ch7/mergeTwoSortedLists.py
552
3.9375
4
from ListNode import ListNode def mergeTwoSortedList(L1, L2): dummyHead = tail = ListNode() while L1 and L2: if L1.data < L2.data: tail.next, L1 = L1, L1.next else: tail.next, L2 = L2, L2.next tail = tail.next tail.next = L1 or L2 return dummyHead.next ...
d713e02c35085bee6fdefd9db1bb46980d990a0b
jcchicom24/pythonExamples
/basicConcepts.py
199
3.59375
4
# comentarios print(3+2) # Operadores simples print (6+4-4) print (6+(4*5)) print ((6*7)/2) #operador exponencial print (2**5) #operador cociente print (20 // 4) #operador del resto print(20 % 6)
f0c13b08eed13b26ab0b18cca0d1bb5b1ffe7fd8
JCUB-CP1404-SP23/a1-movies-to-watch-navsandhu30
/assignment1.py
3,172
3.578125
4
""" Name:Navjot Kaur Date started: 15-12-2019 GitHub URL:https://github.com/JCUB-CP1404-SP23/a1-movies-to-watch-navsandhu30 """ from operator import itemgetter """used intemgetter topic given in reffrence of assignment """ """this will open and read csv movies file """ def movies_file(): in_file = open("movies.csv"...
03cd6f5403d3eb0dbf36ad1c9fc37301ad1c898e
crazymanpj/python
/leetcode/array/array_partition.py
362
3.640625
4
class Solution(object): def arrayPairSum(self, nums): """ :type nums: List[int] :rtype: int """ ret = 0 nums = sorted(nums) for i in range(0, len(nums), 2): ret = ret + nums[i] return ret if __name__ == "__main__": s = Solution() ...
2197604c6ad060659ce05d5456e284a6014644f6
crazymanpj/python
/leetcode/maxarea.py
1,256
3.71875
4
''' 给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) 。在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0)。找出其中的两条线,使得它们与 x 轴共同构成的容器可以容纳最多的水。 说明:你不能倾斜容器,且 n 的值至少为 2。 示例: 输入: [1,8,6,2,5,4,8,3,7] 输出: 49 ''' class Solution(object): def maxArea(self, height): """ :type height: List[int] :rtype: int ...
01b152053478233c66c9ed2d25e5b4b3fe980a85
crazymanpj/python
/test/test_for_numpy.py
252
3.78125
4
#!/usr/bin/env python #encoding=utf-8 # Date: 2017-09-29 # Author: pangjian # version: 1.0 import numpy as np a = np.array([1,2,3,4,5]) a2 = np.array([[1,2,3,4,5], [6,7,8,9,10]]) print a print a2 #行数 print a2.shape[0] #列数 print a2.shape[1]
9063d7d8a2f9eb050b65a79f40ac10f32526bae9
Biltu5/Open-CV
/Lession_4_Five_Essential_function.py
1,001
3.515625
4
import cv2 as cv img = cv.imread('Images/cat.png') # resize img = cv.resize(img,(500,400),interpolation=cv.INTER_AREA) # Converting to Gray Scale gray = cv.cvtColor(img,code=cv.COLOR_BGR2GRAY) cv.imshow('Gray',gray) # Blur [Removing noice from an image] blur = cv.GaussianBlur(img,(7,7),cv.BORDER_DEFAULT) cv.imshow...
8385b7cca4d9d2e2a7d25209233d5462ab8af24c
ErenBtrk/Python-Exercises
/Exercise21.py
723
4.15625
4
''' Take the code from the How To Decode A Website exercise (if you didn’t do it or just want to play with some different code, use the code from the solution), and instead of printing the results to a screen, write the results to a txt file. In your code, just make up a name for the file you are saving to. Extras: ...
f99df6b2eabb591210ef8a18b648deaf198a9ef8
ErenBtrk/Python-Exercises
/Exercise5.py
1,280
4.25
4
''' Take two lists, say for example these two: a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] and write a program that returns a list that contains only the elements that are common between the lists (without duplicates). Make sure your program works on two lists o...
1f9d29eed6d3cde1494c765235f70e06e9c33953
mtoricruz/edabit_practice
/python.py
783
3.984375
4
# U - A SET is a collection of unique items # create a function that sorts through lists removes all dupe items from it # return the new list # assign the newly set list a variable # in that variable, wrap lst parameter in set() function # return variable # P - # new_list = set(lst) # return new_list # E...
9ad606335e461772cf28afde5a3331b170948ea6
j000/Python
/zestaw03/zadanie02.py
427
3.84375
4
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # Jarosław Rymut L = [3, 5, 4] ; L = L.sort() ## okej # x, y = 1, 2, 3 ## nie okej: za dużo wartości, za mało zmiennych # X = 1, 2, 3 ; X[1] = 4 ## nie okej: tupli nie można modyfikować # X = [1, 2, 3] ; X[3] = 4 ## nie okej: zapis poza listą # X = "abc" ; X.append("d...
3e8d739ab8984aa5016303989bfd879a055ba2e2
j000/Python
/zestaw04/zadanie07.py
1,049
3.96875
4
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Jarosław Rymut zadanie 4.7 """ def flatten_recursive(sequence): """ Returns flattened sequence - recursive version >>> flatten_recursive([1, [2, [3]]]) [1, 2, 3] >>> flatten_recursive([]) [] """ out = [] for i in sequence: i...
768652f293c47109183ec0265472a57218d003b5
j000/Python
/zestaw02/zadanie14.py
1,062
4
4
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Jarosław Rymut zadanie 2.14 """ import sys def longest_word(line): """ Returns length and longest word in line. >>> longest_word('test') (4, 'test') >>> longest_word('test numer dwa') (5, 'numer') """ (max_len, max_word) = (0, '') f...
02997ed760ec2c0e6235bee41af9e0e462310e2c
j000/Python
/zestaw13/knight.py
2,277
3.609375
4
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ zadanie 13.1 Wyszukiwanie binarne Jarosław Rymut """ def moves(pos): (x, y) = pos tmp = [ (x + 1, y - 2), (x + 2, y - 1), (x + 2, y + 1), (x + 1, y + 2), (x - 1, y + 2), (x - 2, y + 1), (x - 2, y - 1), ...
fda6ebecb56feb78b47b2586eec3689fb006596d
ubi-naist/RaspberryPi-PoweroffButton
/poweroffbutton.py
1,164
3.5
4
"""poweroffbutton.py will start poweroff routine on pull-down event on a GPIO Pin Configure BUTTON_PIN and LED_PIN variables to valid GPIO labeled number pins. LED pin configuration is Optional Requires: gpiozero Regarding sudo on poweoff() function sudo command on poweroff() is optional It is not required if r...
2f826992c7d43745c16ee98e5dfcbcb2b028dd6d
Dinesh-Sivanandam/LeetCode
/151-reverse-a-string.py
365
3.78125
4
class Solution(object): def reverseWords(self, s): """ :type s: str :rtype: str """ s = s.split() s = s[::-1] s = " ".join(s) return s if __name__ == '__main__': sol = Solution() s = "I am a programmer" re...
e2791867ea5be4baeb1a03d36ca38af730b0be3e
Dinesh-Sivanandam/LeetCode
/234-palindrome-linked-list.py
658
3.765625
4
# Definition for singly-linked list. # class ListNode(object): # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution(object): def isPalindrome(self, head): """ :type head: ListNode :rtype: bool ...
042cdc222e5da07d430c0b6d1cfcc270d7500fdc
Dinesh-Sivanandam/LeetCode
/326-power-of-three.py
509
3.9375
4
class Solution(object): def isPowerOfThree(self, n): """ :type n: int :rtype: bool """ i = 0 ans = 0 if n == 0: return False while ans < n: ans = 0 ans = 3 ** i i+=1 ...
8b53226541e87eaee9b5ad490c425a35d84e3ab6
Dinesh-Sivanandam/LeetCode
/53-maximum-subarray.py
1,083
4.25
4
#Program to find the maximum sum of the array def maxSubArray(A): """ :type nums: List[int] :rtype: int """ #length of the variable is stored in len_A len_A = len(A) #if the length of the variable is 1 then returning the same value if 1 == len_A: return A[0] """ ...
e5cd1c635713fe4b2ef32dc7f47fe659d41a657d
misty-garcia/ds-methodologies-exercises
/regression/evaluate.py
2,967
3.765625
4
# Load the tips dataset from either pydataset or seaborn. import numpy as np import pandas as pd import seaborn as sns import matplotlib.pyplot as plt from math import sqrt from pydataset import data from sklearn.metrics import mean_squared_error, r2_score, explained_variance_score tips = data("tips") # Fit a linear...
db176bafadc9a642fc1836df3aee3df84bc51a28
misty-garcia/ds-methodologies-exercises
/time_series/acquire.py
2,957
3.703125
4
import pandas as pd import requests # Using the code from the lesson as a guide, create a dataframe named items that has all of the data for items. def get_items(): base_url = "http://python.zach.lol" response = requests.get(base_url + "/api/v1/items") items = pd.DataFrame(response.json()["payload"]["items...
428467c8ef97443ff7ba1196cf98f1fbce033540
pipe05/DiscOS
/lol_gui.py
2,533
3.65625
4
#USE A WHITE/LIGHT BLUE BACKGROUND import RPi.GPIO as GPIO GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(26, GPIO.OUT) GPIO.setup(27, GPIO.OUT) GPIO.setup(16, GPIO.OUT) GPIO.setup(6, GPIO.OUT) GPIO.setup(2, GPIO.OUT) GPIO.setup(3, GPIO.OUT) GPIO.setup(4, GPIO.OUT) import time from colorama import Fore GPIO....
71929d852440e9767bed7adf6cb2d1deb9ed93b3
ul-masters2020/CS6502-BigData
/lab_week2/intersection_v1.py
349
4.1875
4
def intersection_v1(L1, L2): '''This function finds the intersection between L1 and L2 list using in-built methods ''' s1 = set(L1) s2 = set(L2) result = list(s1 & s2) return result if __name__ == "__main__": L1 = [1,3,6,78,35,55] L2 = [12,24,35,24,88,120,155] result = intersection_v1(L1, L2) print(f"Inter...
aefe0faa4ce13d415cff28dfdfd1833c5aef9b81
ul-masters2020/CS6502-BigData
/lab_week8/spark1.py
2,327
3.578125
4
import csv from io import StringIO from datetime import datetime from collections import namedtuple from operator import add, itemgetter from pyspark import SparkConf, SparkContext # module constants APP_NAME = "CS6502 Spark Example" DATE_FMT = "%Y-%m-%d" TIME_FMT = "%H%M" fields = ('date', 'airline',...
0aa798e818fba5b9f35f1208d17a1af393800190
rajeshgurbani/python
/python1/TV.py
1,050
3.6875
4
class TV: def __init__(self, name:str, channel:int=1, volumn:int=15): self.name = name self.channel = channel self.volumn = volumn self.isOn = False def start(self): self.isOn = True #print('TV : '+ self.name + 'has started ' + 'channel number : '+ str(self.chann...
261b5d13e3e8a1626aa8cc94d22320225b62a5f4
suhasbms/Login_Page_GUI
/test.py
4,681
3.671875
4
from tkinter import * # class Buttons: # # def __init__(self, master): # frame = Frame(master) # frame.pack() # # self.printButton = Button(frame, text = "Print message", command = self.printMessage) # self.printButton.pack(side = LEFT) # # self.quitButton = Button(frame, t...
c32edf091347fcd472dba962e5b682a128c4036d
Fironn/pami_pykit
/traditional/fpgrowth/fpgrowth_junk.py
8,166
3.953125
4
import sys class Node(object): # Node is class and node is its instance def __init__(self, item, children): #childern self.item = item self.children = children # children is dictionary; key is item name and values is a node haveing same item name self.parent = None # while creating node we ...
e22b8b0118602f46eeb6d10ece21836a7878a806
Olishevko/home_work2
/day_of_week.py
427
4.25
4
day_of_week = int(input('enter the serial number of the day of the week: ')) if day_of_week == 1: print('monday') elif day_of_week == 2: print('tuesday') elif day_of_week == 3: print('wednesday') elif day_of_week == 4: print('thursday') elif day_of_week == 5: print('friday') elif day_of_week == 6: p...
07a8076b69b89106633e805feb181ac54e42d8b1
deepoceansame/Artificial-Intelligence-Berkeley-CS188
/Pro1Imp/NineBlocks.py
5,694
4.15625
4
import heapq class PriorityQueue: """ Implements a priority queue data structure. Each inserted item has a priority associated with it and the client is usually interested in quick retrieval of the lowest-priority item in the queue. This data structure allows O(1) access to the lowest-prio...
8b2ec04aef80d96e472eaf2592d180f41c0b06a2
ABDULMOHSEEN-AlAli/Guess-The-Number
/Guess-The-Number.py
2,895
4.25
4
from random import randint # imports the random integer function from the random module computer_guess = randint(1, 50) # stores the unknown number in a variable chances = 5 # sets the chances available to the user to 5 def mainMenu(): # defines the main menu function, which will be prompted to the user every now an...
7d7ea9cf065fd335fec5a91178b9b28a360e240a
Michaelplata/calculator_test
/week_01/day_2/lists_dictionaries_lab/solution/exercise_d_advanced_logic.py
1,453
4.09375
4
# For the following list of numbers: numbers = [1, 6, 2, 2, 7, 1, 6, 13, 99, 7] # 1. Print out a list of the even integers: even_numbers = [] for number in numbers: if number %2 == 0: even_numbers.append(number) print(even_numbers) # 2. Print the difference between the largest and smallest value: larg...
b28992a7a690206dabb6584b3790d6c647b7d5af
Michaelplata/calculator_test
/week_01/day_3/functions_lab_1/solution/src/python_functions_practice.py
1,326
4.09375
4
def return_10(): return 10 def add(num_1, num_2): return num_1 + num_2 def subtract(num_1, num_2): return num_1 - num_2 def multiply(num_1, num_2): return num_1 * num_2 def divide(num_1, num_2): return num_1 // num_2 def length_of_string(string): return len(string) def join_string(string_1...
7906bb35b5f7c0c0acb8730ff7ccc6423fdd1623
LesroyW/General-Work
/Python-Work/Loops.py
470
4.4375
4
#Looping over a set of numbers # For number in numbers: # print(number) examples of for loop # For loops can also loop of a range #e.g for x in range(5): # print(x) #While loops can also be used within it #Break and continue statements can be used to skip the current block or return to the for/whil statement # el...
fb44ec95efdbaaf9647c6ca8885abb84654a2143
LesroyW/General-Work
/Python-Work/Basic_Operators.py
513
3.765625
4
#Similar to java in terms of addition/Multiplication and division # Similar Symbols for modulo # Two multiplication symbols allows for powers 2 ** 3 is 2 to the power 3 # Concatenation can be done with strings using the addition operator # However compared to Java, python supports multiplying strings to form a string. ...
2594234091f9bbb85595c6c80e47bae55c692553
adityagith/pythonprograms
/read character by character from file.py
389
3.640625
4
file1 = open("file 2.txt") for line in file1: for word in line.split(" "): if(word!='\n'): for character in word: print(character) file1.close() print("\n\nAlternate Method\n\n") file1 = open("file 2.txt") while(1): char = file1.read(1) ...
9b3267d9488f10a980a2935d77bf906c4468f281
adityagith/pythonprograms
/prime number.py
278
4.15625
4
a = int(input("Enter a number to check its prime or not\n")) if(a<=0): print("No") elif(a==2): print("Yes") elif(a>2): for i in range(2,a): if(a%i==0): print("Not a prime") break else: print("Prime")
6453c955410456d50ec84e3efb988a6e82cdc76f
adityagith/pythonprograms
/Python program to interchange first and last elements in a list.py
118
3.546875
4
list = [12,35,9,56,24] temp = list[0] list[0] = list[len(list)-1] list[len(list)-1] = temp print(list)
944a98281edaf785a12229b5f7b92bc54c3e3be9
ry7tam/pyneng-online-11-jun-aug-2021
/examples/14_regex/parse_dhcp_snoop_1.py
557
3.53125
4
import re from pprint import pprint def parse_dhcp_snooping(filename): result = [] regex = ( r"(?P<mac>\S+) +(?P<ip>\S+) +" r"\d+ +\S+ +" r"(?P<vlan>\d+) +(?P<intf>\S+)" ) with open(filename) as f: for line in f: match = re.search(regex, line) if...
2db106ac8bb6a4c009bcb6d2a2f752d183ac89f6
zhenningtan/DataStructure_Algorithms
/quicksort.py
1,452
3.875
4
# quick sort def ChoosePivot(arr): return arr[0] # pick the first element #return arr[-1] # pick the last element #return median([arr[0], arr[-1], arr[len(arr)/2]]) def Partition(arr): i = 1 for j in range(1, len(arr)): if arr[j] < arr[0]: arr[i], arr[j] = arr[j], arr[i] ...
3fe6eb252a60edfa06b9c96e8bdc4728bb0537a7
zhenningtan/DataStructure_Algorithms
/mergesort_inversion.py
1,462
4.15625
4
############################################################ # Count inversion # merge sort function def merge_inversion(arr1, arr2, inversion): n1 = len(arr1) n2 = len(arr2) n = n1 + n2 marray = [0] * n k = 0 i = 0 j = 0 #compare arr1 and arr2 and add the smaller number to the sorted ...
61236c3b2df1e28c3f92c0694d721eec5b27c8ac
xeonye/TT_ML
/singleLearning/NB.py
1,122
3.5625
4
#coding:utf-8 ''' 模块设计目的:朴素贝叶斯 GaussianNB(高斯朴素贝叶斯)、MultinomialNB(多项式朴素贝叶斯)、BernoulliNB(伯努利朴素贝叶斯) @author:Jeeker ''' def NB_normal(x_train,y_train,modelName='MultinomialNB'): import numpy as np from sklearn.naive_bayes import MultinomialNB from sklearn.naive_bayes import GaussianNB from sklearn.naive_bay...
748031284eb19fb2c5dce648b3e70f8d3075b469
jonalynnA/IntroToPythonIIGuided
/Functions.py
325
3.75
4
def my_function(): print("Hi") my_function() def another_function(a): print(f"1: {a}") a += 5 print(f"2: {a}") a = 12 another_function(a) print(a) def next_function(a): print(f"1: {a}") a[0] = 99 print(f"2: {a}") a = [0, 1, 2, 3, 4] next_function(a) print(a) # integers are not mut...
009126076d3136b6356366c579cce51a87056d5f
gregimba/inventory
/inventory.py
1,204
3.59375
4
from peewee import * from money import Money from datetime import date import click db = SqliteDatabase('inventory.db') class Item(Model): name = CharField() value = CharField() location = CharField() quantity = IntegerField() notes = TextField() date = DateField() class Meta: da...
d288b556c3bc6444d2c7f43d0045396fdbfbdc35
natebakescakes/edx-6.00.1x-problem-sets
/problem_set_5/problem_6.py
860
3.921875
4
def swapSort(L): """ L is a list on integers """ count = 0 print "Original L: ", L for i in range(len(L)): for j in range(i+1, len(L)): if L[j] < L[i]: # the next line is a short # form for swap L[i] and L[j] L[j], L[i] = L[i], L[j] ...
44c2ac9098e6c39746f38c80f8dd6d35f34c3624
natebakescakes/edx-6.00.1x-problem-sets
/lecture/lecture_3p9.py
607
3.953125
4
running = True high = 100 low = 0 print ('Please think of a number between 0 and 100!') while running: ans = (high + low) / 2 print ('Is your secret number %s' % ans) response = raw_input('Enter \'h\' to indicate the the guess is too high. Enter \'l\' to indicate the guess is too low. Enter \'c\' to ...
5b565c7f6d2c351ea87a3449822a49fed530325b
RookieZW/LintCode
/41最大子数组/最大子数组.py
750
3.953125
4
''' 给定一个整数数组,找到一个具有最大和的子数组,返回其最大和。 样例 样例1: 输入:[−2,2,−3,4,−1,2,1,−5,3] 输出:6 解释:符合要求的子数组为[4,−1,2,1],其最大和为 6。 样例2: 输入:[1,2,3,4] 输出:10 解释:符合要求的子数组为[1,2,3,4],其最大和为 10。 挑战 要求时间复杂度为O(n) 注意事项 子数组最少包含一个数 ''' class Solution: """ @param nums: A list of integers @return: A integer indicate the sum of max subarray ...
92821e8ea3fe68285ad48579170508efe197bbb9
RookieZW/LintCode
/13查找子串/查找子串.py
1,275
3.5
4
''' 对于一个给定的 source 字符串和一个 target 字符串,你应该在 source 字符串中找出 target 字符串出现的第一个位置(从0开始)。如果不存在,则返回 -1。 样例 样例 1: 输入: source = "source" , target = "target" 输出:-1 样例解释: 如果source里没有包含target的内容,返回-1 ''' class Solution: """ @param source: @param target: @return: return the index """ def getNext(self, ...
0550bfdd114f34e3c338764d5bddb65e9844e229
RookieZW/LintCode
/457经典二分查找问题/经典二分查找问题.py
725
3.96875
4
class Solution: """ @param nums: An integer array sorted in ascending order @param target: An integer @return: An integer """ def findPosition(self, nums, target): # write your code here nums_len = len(nums) if nums_len == -1: return -1 middle = nums_l...
dd3e4a5ea22e9f60af7f463f937c91f52ea33e05
RookieZW/LintCode
/45最大子数组差/最大子数组差.py
1,402
3.765625
4
''' 给定一个整数数组,找出两个不重叠的子数组A和B,使两个子数组和的差的绝对值|SUM(A) - SUM(B)|最大。 返回这个最大的差值。 样例 例1: 输入:[1, 2, -3, 1] 输出:6 解释: 子数组是 [1,2] 和[-3].所以答案是 6. 例2: 输入:[0,-1] 输出:1 解释: 子数组是 [0] 和 [-1].所以答案是 1. 挑战 时间复杂度为O(n),空间复杂度为O(n) 注意事项 子数组最少包含一个数 ''' class Solution: """ @param nums: A list of integers @return: An integer indica...
379a96400b033254a0ddd01c9a477882d16adfd0
odecay/CS112-Spring2012
/hw04/sect1_if.py
992
4.25
4
#!/usr/bin/env python from hwtools import * print "Section 1: If Statements" print "-----------------------------" # 1. Is n even or odd? n = raw_input("Enter a number: ") n = int(n) x = n % 2 if x == 0: print "1.", n, "is even" else: print "1.", n, "is odd" # 2. If n is odd, double it if x > 0: ...
794aef9fb7d07f59d5ceab52d1188a28cfbc50d7
odecay/CS112-Spring2012
/hw05/nims.py
1,063
3.875
4
#!/usr/bin/env python """nims.py A simple competitive game where players take stones from stone piles. """ stoneNumb = int(raw_input("input total stones: ")) maxTake = int(raw_input("input max number of stones to take per turn: ")) pTurn = 1 lessTotal = 0 print "started a new game" print "number of sto es in the pile...
0e52a9c51d4846a333df94065ced314888dffc33
Kalu78/Projet-Python_Matchmaking
/morpion.py
4,654
3.5625
4
import pygame, sys import numpy as np pygame.init() WIDTH = 600 HEIGHT = 600 LINE_WIDTH = 15 BOARD_ROWS = 3 BOARD_COLS = 3 CIRCLE_RADIUS = 60 CIRCLE_WIDTH = 15 CROSS_WIDTH = 25 SPACE = 55 BG_COLOR = (243, 139, 87) LINE_COLOR =( 255, 190, 158 ) CIRCLE_COLOR = (239, 239, 200 ) CROSS_COLOR = (0, 0, 0 ) screen = pygam...
0affdae9e91a262aac7d8a8307b4370d97d3ed7f
FabioInternicola/Kurti
/calculator.py
1,507
4
4
import os import math fcolor = open('color','r') color = fcolor.read() fcolor.close() os.system('color %s' % color) print("0: Done\n1: Addition\n2: Subtration\n3: Moltiplication\n4: Division\n5: Elevating power\n6: Square root\n") operation = input("Number of the operation: ") if operation == '0': print('O...
eb14ca212787ef16d8810039e13de536315999a9
siva4646/DataStructure_and_algorithms
/python/matrix/spiral_matrix_navigation.py
1,514
3.59375
4
class Solution: def spiralOrder(self, matrix: List[List[int]]) -> List[int]: dir=0 left=0 right=len(matrix[0])-1 top=0 bottom=len(matrix)-1 ret=[] while (top<=bottom and left<=right): if dir==0: print ('left,right',left,ri...
2584097aff364d6aeb60030eda2117628cbceda9
siva4646/DataStructure_and_algorithms
/python/string/longest_word_indictioary_through_deleting.py
986
4.15625
4
""" Given a string and a string dictionary, find the longest string in the dictionary that can be formed by deleting some characters of the given string. If there are more than one possible results, return the longest word with the smallest lexicographical order. If there is no possible result, return the empty string....
a084fef7c288035fa930b133b64f240d132865e0
siva4646/DataStructure_and_algorithms
/python/matrix/searchSortedMatrix.py
386
3.71875
4
def searchInSortedMatrix(matrix, target): # Write your code here. result=[-1,-1] result_flg=0 for i in range(len(matrix)): for j in range(len(matrix)+1): print (i,j,matrix[i][j]) result_flg=1 if matrix[i][j] == target else 0 if matrix[i][j]<target else 2 if result_flg==1: return [i,j] elif re...
554d3081206eeb48044b306717dac3f6dae44594
brahmaniraj/Python_BM
/Datatypes/Strings/isalnum.py
220
3.765625
4
#!usr/bin/python """ str1 = " " print("Alpha and numeric values test : ",str1.isalnum()) str2="Python word ....!!!" print(str2.isalnum()) a='20' b="ab" print(a.isalnum()) print(b.isalnum()) print(a.isdigit()) """
56375c22f2032a6353fc775a5c7a5b953d415a50
brahmaniraj/Python_BM
/Functions/Overview_functions.py
814
4.0625
4
""" A function is a block of organized, reusable code that is used to perform a single, related action. Functions provide better modularity for your application and a high degree of code reusing. As you already know, Python gives you many built-in functions like print(), etc. but you can also create your own functions....
9b90a92ae8019fb0f7b7ea91381269abc8df48dc
brahmaniraj/Python_BM
/Datatypes/Strings/capitalize.py
428
4.6875
5
#!/usr/bin/python # 1. capitalize() Method : # Note: string with only its first character capitalized. a01 = "welcome to python world" a02 = "python world" a03 = "to python world" print ("a01.capitalize() : ", a01.capitalize(),id(a01),type(a01),len(a01)) print("") print ("a02.capitalize() : ", a02.capitalize(),id(a...
fae94793aa2d27112bb61b86472503514efc29e3
brahmaniraj/Python_BM
/Datatypes/Strings/format_method_stringspecial.py
339
3.546875
4
first_name = "brahmani" middle_name = "raj" last_name = "moturu" print(" Firstname :{} Middle Name : {} Lastname : {}".format(first_name,middle_name,last_name)) print("First Name : {0} Last Name :{1} AccountID : {2}".format("Brahmani","Raj",10203040)) print ("Value1 {a} Value2 {b} and Value3 {c}".format(a="python",...
8c85d7d7c05c72662a59087e48230b61f59a008a
brahmaniraj/Python_BM
/ExceptionHandling/Example_exception.py
876
4.0625
4
""" a=input("enter numner1: ") b=input("enter numner2: ") c= int(a)/int(b) print("division is:" ,c) #will throw an error - c= int(a)/int(b) #ZeroDivisionError: division by zero """ """ a=input("enter numner1:") b=input("enter numner2:") try: c=int(a)/int(b) except Exception as e: print(f'Exception occur...
4e5679650b124195ef62e1bc8e2da1372e80a47d
sandeepit151/simple-programs
/simplePython/dllFromTernaryTree.py
3,449
4.59375
5
#Represent a node of ternary tree class Node: def __init__(self,data): self.data = data; self.left = None; self.middle = None; self.right = None; class TernaryTreeToDLL: def __init__(self): #Represent the root of ternary tr...
e7deb9abc4a38bb16b98434f7aa4c53f31488f00
benlvn/flask_guides
/thenewboston/tutorial2_Routing.py
854
3.75
4
from flask import Flask app = Flask(__name__) # @ signifies a decorator - way to wrap a function and modify its behavior # we use this to map a url to a return value @app.route('/') def index(): return 'This is the homepage' # Go to localhost/tuna @app.route('/tuna') def tuna(): return '<h2>Tuna is good</h2>' ...
2e274a24f93f81017686ad4c5ceabfaece95d419
sebasbeleno/ST0245-001
/laboratorios/lab02/codigo/laboratorio2.py
1,610
4.15625
4
import random import sys import time sys.setrecursionlimit(1000000) # Function to do insertion sort def insertionSort(arr): # Traverse through 1 to len(arr) for i in range(1, len(arr)): key = arr[i] # Move elements of arr[0..i-1], that are # greater than key, to one posi...
baefc72d4459204dcd5473e6d13b2883942fc66c
sebasbeleno/ST0245-001
/talleres/taller02/Suma_grupo.py
266
3.515625
4
def Suma_grupo(start, nums, target): if (start >= len(nums)): return target == 0 add = Suma_grupo(start+1, nums, target - nums[start]) add_not = Suma_grupo(start+1, nums, target) return add or add_not print(Suma_grupo(0,[2, 5, 3],10))
4b99a94459a7b5b90b140cec8e1dc4fd503dced0
sebasbeleno/ST0245-001
/talleres/taller08/taller8.py
2,257
3.609375
4
from collections import deque def polaca(entrada): entrada = entrada.split() pila = deque() operadores = "+*/-" for i in range(0, len(entrada)): if entrada[i] in operadores: elDeArriba = pila.pop() elPenultimo = pila.pop() opera...
ef61170baa1eb2b9da9f2444f5a829029f664642
Edinburgh-Genome-Foundry/Plateo
/plateo/exporters/plate_to_tables.py
3,820
3.609375
4
from collections import defaultdict from ..tools import number_to_rowname, unit_factors import pandas def plate_to_platemap_spreadsheet(plate, wellinfo_function, filepath=None, sheet_name='plate_map', headers=True): """Generate a spreadsheet with a map of the plate. Parameter...
c4eb110408af79cdd757c99e8f9de52df667c9ab
VenkteshV/grokking-algorithms-exercises
/factorial-tail-recursion.py
151
3.75
4
def factorial(n, accumulator =1): if n ==0: return accumulator else : return factorial(n-1, accumulator*n) print(factorial(6))
ac64aef9e03bc087d53d709a3735979b2a71aac1
codin-eric/pj_generator_dnd
/main.py
1,926
3.828125
4
''' Coding-eric video 8 Mi año como un Peronaje de Rol ''' ''' Debemos tirar 4 dados y quedarnos con la suma de los 3 mejores ''' import random dado1 = random.randint(1,6) dado2 = random.randint(1,6) dado3 = random.randint(1,6) dado4 = random.randint(1,6) # if(dado1 < dado2 and dado1 < dado3 and dado1 < dado4): #...
779c966bfe04bcc269cfdc85ce95281b28579f53
atrueresistance/PySciEngie
/CH02-Numpy/list_comp.py
526
3.796875
4
#!/usr/bin/python from __future__ import print_function from __future__ import division from __future__ import absolute_import import numpy as np x = [5,10,15,20,25] #init y = [] for cnt in x: y.append(cnt/5) print("\nOld fashioned way: x = {} y = {}\n".format(x,y)) z = [n/5 for n in x] print("List Comprehensi...
95a70e4add1c47c207a5a174ad66a5554367fd39
nicholas-shepard/CSCI-136
/2-8-19-lab.py
1,118
3.90625
4
############### BOARD WORK ################## #class parentClass: # def printString(aString): # print(aString) #class childClass(parentClass): # def printString(aString): # super().printString(aString) #a = childClass #a.printString("A") #def lastOddRec(anArray): # if anArray[0] % 2 == 1: # ...
133fed4b7c21e173dd62da311752ee874ec9762c
nicholas-shepard/CSCI-136
/hw-01-15/1.2.4.py
123
3.515625
4
#Variables a = 5.56 b = 5.56 #Initial statement print((not (a < b) and not (a > b))) #Simplified statement print(a == b)
0fc2872e571dfd7765367304ead0d7b1c3cbbd94
nicholas-shepard/CSCI-136
/hw-02-11/shortString.py
269
3.5
4
def shortString(a): if a == []: return None return shortStringHelper(a, a[0]) def shortStringHelper(a, b): if a == []: return b if len(a[0]) < len(b): return shortStringHelper(a[1:], a[0]) return shortStringHelper(a[1:], b)
fca4ad12d59963048ffda4e87b01c8a7842e7ab6
arq101/Suitable-Places-To-Eat
/main.py
2,964
3.5
4
import argparse import pandas as pd from pathlib import Path from typing import Dict, Optional import json def arg_parser() -> argparse.Namespace: """Process command line arguments """ parser = argparse.ArgumentParser(description='finds safe places to eat for team members') parser.add_argument('-o', '...
aad4351267719c879442d356f05edea4d6ec53f5
dhruvmanila/terminal-games
/hangman/main.py
13,070
3.71875
4
import json import random from itertools import chain from string import ascii_lowercase, digits, punctuation, whitespace from typing import Iterable, Tuple # Globals INSTRUCTION_FILENAME = "instructions.txt" WORDS_FILENAME = "words.json" INPUT_CHECK = punctuation + digits + whitespace VOWELS = "aeiou" LINE_SEP = "-" ...
4a25fe54861de24a479a473430dff4880eb06b33
faithngetich/andela_bootcamp
/oop/oop_lab.py
460
4.0625
4
class Car: def __init__(self): self.doors = 4 def get_doors(self): print(self.doors) #Ferrari inherits from Car class Ferrari((Cars)): def __init__(self): self.doors = 2 #data in the Car and Ferrari class is encapsulated in the peugot and ferrari object Peugot = Car() Ferrari = Ferrari() #Polymorp...
bb3eba451d37b95ef160bb0cd1785ac822a6c009
jblespiau/Rauzy-Language
/modeling/model.py
7,899
3.859375
4
r""" .. module:: model The model module contains only the Model class which allows to load and save models. Loading a model from a file:: >>> from modeling.model import * >>> loaded_model = Model.load('examples/car.model') Saving a model from a file:: >>> from modeling.model import * >>> loaded_model = Mod...
d969a5f40bd535ed9141ecdd277c437f7be232e8
nerincon/Python-Exercises
/.~c9_invoke_5h2f0.py
1,448
3.78125
4
# Phonebook Dictionary phonebook_dict = { 'Alice': '703-493-1834', 'Bob': '857-384-1234', 'Elizabeth': '484-584-2923' } print(phonebook_dict.get("Elizabeth")) phonebook_dict["Kareem"] = "938-489-1234" print(phonebook_dict) del phonebook_dict["Alice"] print(phonebook_dict) phonebook_dict["Bob"] = "968-345-2345" p...
38bd89e50954a7421eee5662d019fc303fa1b172
nerincon/Python-Exercises
/week2/Thurs/phonebook_app/phonebook_json.py
2,283
4.15625
4
import json while True: print("Electronic Phone Book") print("=====================") print("1. Look up an entry") print("2. Set an entry") print("3. Delete an entry") print("4. List all entries") print("5. Save entries") print("6. Restore saved entries") print("7. Quit") ...
65e2adf12fba65fb46fee9759729360caf99839e
Christin-Plakkal/Python-zero-to-hero
/day1/3.fstr.py
60
3.65625
4
num = 10 str = "hi" print(f"{str} Arun your age is {num}")
8d4aa5fdfc4da1f6c3ac85a3d40be2f75ce4aaf8
19002750/Skripsie2018
/GetVectors.py
3,011
3.515625
4
import numpy as np def get_coords(A, B): """A and B must contain the coordinates of origin , x-axis,y-axis and z-axis both with respect to the same reference frame. A = [origin ] [x = (x,y,z)] [y = (x,y,z)] [z = (x,y,z)] ,each ha...
a9e927b36b3e1bcfbd59e16d02324f240c73ea45
alfagama/arxiv_predicting_paper_category
/dataset/dataset_methods.py
2,214
3.546875
4
import pandas as pd from sklearn.model_selection import train_test_split # Options for pandas ----- pd.set_option('display.max_columns', None) pd.set_option('display.max_rows', None) def get_preprocessed_dataset(): """ read preprocessed dataset from directory: "../data/preprocessed_dataset.csv" :ret...
41ff3b6329099e80f4fae257092d4569188ffcbf
karankrw/LeetCode-Challenge-June-20
/Easy/Reverse_string.py
823
4.09375
4
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Fri Jun 5 00:18:03 2020 @author: karanwaghela """ """ Write a function that reverses a string. The input string is given as an array of characters char[]. Do not allocate extra space for another array, you must do this by modifying the input array in-p...
afd31e371feaed5fdf84e4372460b931416b3284
karankrw/LeetCode-Challenge-June-20
/Week 3/Dungeon_Game.py
1,918
4.3125
4
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Jun 22 01:25:32 2020 @author: karanwaghela """ """ The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was initially po...
65e2218d8c74f5885b0a55158e5da587d83566c0
sulemigoreng/learn-python
/read-file.py
380
3.78125
4
''' r read r+ read and write w write a append ''' employee_file = open("employees.txt", "r") print(employee_file.readable()) # return a boolean value whether the file is readable or not # print(employee_file.readline()) # print(employee_file.readline()) # print(employee_file.readlines()) for employee in employee_...
da379de0df0857056074dfda5d0740c76ee00169
SylvieGa/homework13_14
/football_basketball.py
812
3.9375
4
print("Enter some football player's data!") f_name = input("Enter player's first name: ") l_name = input("Enter player's last name: ") height = input("Enter player's height: ") weight = input("Enter player's weight: ") goals = input("Enter the number of player's goals: ") y_cards = input("Enter the number of player's ...