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
3ea56c235b6eece5fc384ab4c5a9cdd96411994b
Jethet/Practice-more
/python-katas/EdabFormatNum.py
415
3.78125
4
# Create a function that takes a number as an argument and returns a string # formatted to separate thousands. def format_num(n): n = str(n) if len(n) >= 7: return n[0:-6] + ',' + n[-6:-3] + ',' + n[-3::] if len(n) >= 4: return n[0:-3] + ',' + n[-3::] else: return n print(fo...
9246abae7135a9a61f01cc3db5056c8794005b16
Jethet/Practice-more
/python-katas/EdabSumLowest.py
598
3.9375
4
# Create a function that takes a list of numbers and returns the sum of the two # lowest positive numbers. Don't count negative numbers. def sum_two_smallest_nums(lst): new_lst = [x for x in lst if x >= 0] return sum((sorted(new_lst))[0:2]) print(sum_two_smallest_nums([19, 5, 42, 2, 77])) # 7 print(sum_two_s...
e1f9d808a5e5a24c70ff76991e377b64121594ca
Jethet/Practice-more
/python-katas/EdabCap.py
581
3.90625
4
# Create a function that takes a list of names and returns a list with the # first letter capitalized. Order of the original list cannot be changed. # Note: MABELLE is returned Mabelle def cap_me(lst): new_lst = [x.lower() for x in lst] return [x.capitalize() for x in new_lst] print(cap_me(["mavis", "senaid...
22800ea3b59510039284cf345034c94c1ee4b99a
Jethet/Practice-more
/python-katas/3_Sum.py
239
4.1875
4
# Return sum of two int, unless values are the same: then return double. def sum_double(a, b): if a == b: return 2 * (a + b) else: return a + b print(sum_double(1,2)) print(sum_double(3,2)) print(sum_double(2,2))
8632fdf9314aac9dee2263361f8f2270d1018096
Jethet/Practice-more
/python-katas/37_Sum2.py
354
3.984375
4
# Given an array of ints, return the sum of the first 2 elements. # If the array is less than 2, sum up the elements that exist, # returning 0 if the array is length 0. def sum2(nums): if len(nums) >= 2: return sum(nums[0:2]) if len(nums) < 2: return sum(nums) print(sum2([1, 2, 3])) print(sum...
3f0aa8fd1025b9f1d919f544cbf78dbc91c44699
Jethet/Practice-more
/python-katas/EdabAltCaps.py
362
4.4375
4
# Create a function that alternates the case of the letters in a string. # The first letter should always be UPPERCASE. def alternating_caps(txt): print(alternating_caps("Hello")) # "HeLlO" print(alternating_caps("Hey, how are you?")) # "HeY, hOw aRe yOu?" print(alternating_caps("OMG!!! This website is awesome!...
394c0e41664f79b95e279ff063f7584a49f675cf
Jethet/Practice-more
/python-katas/EdabCountUniq.py
384
4.28125
4
# Given two strings and a character, create a function that returns the total # number of unique characters from the combined string. def count_unique(s1, s2): return len(set(s1 + s2)) print(count_unique("apple", "play")) #➞ 5 # "appleplay" has 5 unique characters: # "a", "e", "l", "p", "y" print(count_unique("so...
0b1a24700f8f1dd9cdfe3f1d2b5460a49d096495
Jethet/Practice-more
/python-katas/65_Sum13.py
799
3.953125
4
# Return the sum of the numbers in the array, returning 0 for an empty array. # Except the number 13 is very unlucky, so it does not count and numbers that # come immediately after a 13 also do not count. def sum13(nums): sum = 0 if len(nums) > 0 and nums[0] != 13: sum = nums[0] for i in range(...
bf73bd5eda0d1303716e539c0d40f57d6ab13de8
Jethet/Practice-more
/python-katas/57_CountHi.py
378
4
4
# Return the number of times the string 'hi' appears in a given string. def count_hi(str): return str.count('hi') # CodingBat solution: def count_hi(str): sum = 0 for i in range(len(str)-1): if str[i:i+2] == 'hi': sum += 1 #or: sum = sum + 1 return sum print(count_hi('abc hi ...
109882a6a424fd05896640c569221c87280835a7
Jethet/Practice-more
/python-katas/PNCheckKey.py
420
3.828125
4
# Iterate a given list and check if a given element already exists in a # dictionary as a key’s value, if not delete it from the list. rollNumber = [47, 64, 69, 37, 76, 83, 95, 97] sampleDict = {'John':47, 'Emma':69, 'Kelly':76, 'Jason':97} rollNumber[:] = [item for item in rollNumber if item in sampleDict.values()] ...
e398b42c4309d60d59ea97a5e341532502fb0a1c
Jethet/Practice-more
/python-katas/EdabIndex.py
686
4.375
4
# Create a function that takes a single string as argument and returns an # ordered list containing the indexes of all capital letters in the string. # Return an empty array if no uppercase letters are found in the string. # Special characters ($#@%) and numbers will be included in some test cases. def indexOfCaps(wor...
e79e52b336b37444bcdc95b151c50e080e8ab2e3
Jethet/Practice-more
/python-katas/28_Last2.py
300
4.15625
4
# Given a string, return the count of the number of times that a substring # length 2 appears in the string and also as the last 2 chars of the string, # so "hixxxhi" yields 1 (we won't count the end substring). def last2(str): x = str[-2:] return str.count(x) - 1 print(last2('axxxaaxx'))
3837c735626d9ea89162da3f3f15e3514bcd859a
Jethet/Practice-more
/python-katas/EdabCheckEnd.py
646
4.5
4
# Create a function that takes two strings and returns True if the first # argument ends with the second argument; otherwise return False. # Rules: Take two strings as arguments. # Determine if the second string matches ending of the first string. # Return boolean value. def check_ending(str1...
c62e2c73aaec652d3c73d1ef8bfea233f8490726
Jethet/Practice-more
/python-katas/Edab4ltrs.py
461
3.6875
4
# Create a function that takes a list of strings. # Return all words in the list that are exactly four letters. def isFourLetters(lst): my_list = [] for x in lst: if len(x) == 4: my_list.append(x) return my_list print(isFourLetters(["Ryan", "Kieran", "Jason", "Matt" ])) # ["Ryan", "Ma...
d89f0325138991b2de4cf2e7ce83103a70986ed9
Jethet/Practice-more
/python-katas/5_Noise.py
306
3.75
4
#Parrot noise: before 7 or after 20 return True. Parameters: hour and noise def parrot(noise, hour): if noise is True: if hour < 7 or hour > 20: return True if noise is False: return False else: return False print(parrot(True, 7)) print(parrot(True, 20))
13907bfe641d91cf84c72f40e0cabbccfef7c5ab
Jethet/Practice-more
/python-katas/EdabDouble.py
327
4.0625
4
# Create a function that takes a string and returns a string in which each # character is repeated once. def double_char(txt): return ''.join([x*2 for x in txt]) print(double_char("String")) # "SSttrriinngg" print(double_char("Hello World!")) # "HHeelllloo WWoorrlldd!!" print(double_char("1234!_ ")) # "11223344!...
a6d32a7dd42cb061176805ba236a2a231c25da32
Jethet/Practice-more
/python-katas/46_AlarmClock.py
789
4.0625
4
# Given a day of the week encoded as 0=Sun, 1=Mon, 2=Tue, ...6=Sat, and a # boolean indicating vacation, return a string of the form "7:00" indicating # when the alarm clock should ring. Weekdays, the alarm should be "7:00" # and on the weekend it should be "10:00". # On vacation weekdays it should be "10:00" and weeke...
baf3c6195df0fc2638e72ae9f9bf4be5bba73e38
Jethet/Practice-more
/python-katas/EdabTrunc.py
684
4.3125
4
# Create a one line function that takes three arguments (txt, txt_length, # txt_suffix) and returns a truncated string. # txt: Original string. # txt_length: Truncated length limit. # txt_suffix: Optional suffix string parameter. # Truncated returned string length should adjust to passed length in parameters ...
bd0304c63470267b120d29de75b00b480960a0a7
Jethet/Practice-more
/python-katas/EdabAddInverse.py
333
4.125
4
# A number added with its additive inverse equals zero. Create a function that # returns a list of additive inverses. def additive_inverse(lst): print(additive_inverse([5, -7, 8, 3])) #➞ [-5, 7, -8, -3] print(additive_inverse([1, 1, 1, 1, 1])) #➞ [-1, -1, -1, -1, -1] print(additive_inverse([-5, -25, 35])) #➞ [5, 25...
5797703b59a09ee3915451417c6e4205feb47ee5
Marhc/py_praxis
/hello.py
1,590
4.4375
4
"""A simple **"Hello Function"** for educational purposes. This module explores basic features of the Python programming language. Features included in this module: - Console Input / Output; - Function Definition; - Module Import; - Default Parameter Values; - String Interpolation (**'fstrings'**)...
d5c493fcff965a76e3cdeba2b915d26f87fed4ce
OksanaHB/HomeWorksPythonCourse
/CodeWars/reversing_words_in_string.py
84
3.53125
4
def reverse(st): st = ' '.join(list(reversed(str(st).split(' ')))) return st
77d1a326ecad23d41402b8bf4d895d206666e036
Hazem-ali/PSET6-CS50
/credit/credit.py
1,464
3.6875
4
from cs50 import get_string def main(): codestring = get_string("Number: ") code = int(codestring) cardtype(code) def getLuhn(code): # codestr 4003600000000014 code1 = int(code / 10) summation = 0 while int(code1) > 0: condition = 2 * (code1 % 10) if condition >= 10: ...
41bbb28368ac044adb6063cdcf06115c4553f05b
wangchunhala/AU332-SJTU-AI-homework
/Homework1/UniformCostSearch.py
6,671
4.09375
4
# -*- coding: utf-8 -*- from queue import LifoQueue from queue import Queue from queue import PriorityQueue class Graph: """ Defines a graph with edges, each edge is treated as dictionary look up. function neighbors pass in an id and returns a list of neighboring node """ def __init__(sel...
87bd3a9108e13aaa56a823c52709f61279d2c1f9
jorge-coria/Python-Journey
/f-string review.py
494
3.828125
4
# Reviewing f-strings and how they make string interpolation simpler val = 'Silly' print(f"{val} was feeling {val} throughout the performance.") # f-strings are faster than % formatting and str.format() name = 'Isaac' location = 'Paris' age = 10 print(f"{name} couldn't believe he'd made it to {location} at {age}!") #...
a91dce6afa2de589938d0f0e66bc2ef771c1a51a
sriemineni/IntroToProg-Python
/Customer.py
854
3.5625
4
import Persons if __name__ == "__main__": raise Exception("This file is not meant to run by itself") class Customers(Persons.Person): # --Constructor-- def __init__(self, Id="", FirstName="", LastName=""): # Attributes self.__Id = Id #set the property self.Id - Id ...
ce8c0104114b720086ef19476a0c79fdda94305a
dorbirendorf/interview_challenges
/clockHandAngle.py
251
3.609375
4
def calc_angle(time): hour=int(time.split(':')[0])%12 min=int(time.split(':')[1]) hour_angle=((60*hour+min)/2) min_angle=min*6 diff_angle=abs(hour_angle-min_angle) return diff_angle print(calc_angle('07:28'))
6f9f21a171deb5f01b7371af6f0404388f430484
CookyChou/fluent_python
/class2/sorted.py
241
3.859375
4
fruits = [7, 1, 3, 4, 5, 6] colors = ["black", "yellow", "red", "blue"] print(sorted(fruits)) # list.sort(fruits) # print(fruits) print(sorted(fruits, reverse=True)) print(sorted(colors, reverse=True, key=len)) print(sorted(colors, key=len))
110d25970ab72d9ae2f1f848190e434cf4fa5e80
Ilya37/pythontutor
/task02.03.py
125
3.5625
4
d= int(input()) a= int(input()) b= int(input()) c= int(input()) if (a+b+c+d) % 2 == 0: print('YES') else: print('NO')
7a217e8e503b92104d8fb41325b8967d136cab2b
Taehwan0722/Algorithm
/2018 KAKAO BLIND RECRUITMENT/[3차] 압축.py
385
3.546875
4
def solution(msg): answer = [] dic = {chr(ord('A') + i):i + 1 for i in range(26)} word = '' num = 27 for idx, c in enumerate(msg): word += c if word not in dic: answer.append(dic[word[:-1]]) dic[word] = num word = word[-1] num += 1...
61ee0b5e5fc8afdd4a5a7e68716459874d3ded82
agudelodiego/FileManager
/App.py
5,002
3.703125
4
''' REALIZADO POR: Diego Alexander Agudelo Garcia FECHA: 05/Oct/2021 FINALIDAD: El presente archivo tiene como objetivo diseñar el codigo para el programa encargado de interactuar con el usuario, dicho programa sera la interfaz que comunique el Programa Catalogo.py con el usuario. Este programa constara de dos funcion...
f6c2cbf9e372ed0e5b1e3e4fecc00cbf5e7e8e8a
chs2147/PYTHON_EverybodysPython
/socket/simple_socket_server.py
1,629
3.625
4
""" Simple socket server using threads """ import socket import sys from threading import * server_address = ('localhost', 8888) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) print('socket created') # bind socket to local host and port try: s.bind(server_address) except socket.error as msg: prin...
958daa8d8c8452ac4ce0235479fab47f8644739b
bearylogical/ga-assignments
/project_3/subreddit_app/utilities.py
787
3.53125
4
import regex as re from nltk.corpus import stopwords stops = set(stopwords.words('english')) def clean_text(text): # 01 convert titles, selftext into lowercase lower_text = text.lower() no_br_paret_text = re.sub(r'\(.+?\)|\[.+?\]', ' ', str(lower_text)) # 03 remove special characters removed_spe...
1ba9990fa230bf4e4d4891eaa9d8d7ce6814ddcd
yusuke-matsunaga/adc2019lite
/core/position.py
2,890
3.671875
4
#! /usr/bin/env python3 """Position の実装ファイル :file: position.py :author: Yusuke Matsunaga (松永 裕介) Copyright (C) 2019, 2020 Yusuke Matsunaga All rights reserved. """ class Position: """位置を表すクラス 内容はただの (x, y) のタプル ただし +/- や +=/-= の演算を定義している. また,メンバ変数は初期化時に設定された後は +=/-=演算以外では変更されない. :param int ...
26bdcdfb2eceb5eb3e067842b6b6094390495101
RalphBacon/219-Raspberry-Pi-PICO-Sound-Generation
/First Beep.py
1,013
3.5625
4
# Import the required 'libraries' for pin definitions and PWM from machine import Pin, PWM # Also import a subset for sleep and millisecond sleep. If you just import # the utime you will have to prefix each call with "utime." from utime import sleep, sleep_ms # Define what the buzzer object is - a PWM output o...
1fdf6bb9d77246ede72c93fd6b57ef78d3ded55f
Wigsinator/CSC263
/src/ps2/triangle.py
1,712
4.03125
4
''' CSC263 Winter 2020 Problem Set 2 Adapted from Starter Code University of Toronto Mississauga ''' # Do NOT add any "import" statements from math import floor #Approved by Suschant https://mcsapps.utm.utoronto.ca/forum/t/ps2-q4-can-we-import-floor/5249/2 # Do NOT use Python dictionaries class TriangleHash...
836d4d6b51f26e17db522e7f86ea56ab0fd78495
rahulkrishnan221/DataStructure_Algo_Implementations
/huge_fibo_modulo_m.py
389
3.59375
4
def pisiano_period(m): a=0 b=1 for i in range(0,m*m): c=(a+b)%m a=b b=c if a==0 and b==1: return i+1 def Huge_Fib(n,m): remain=n%pisiano_period(m) a=0 b=1 c=remain for i in range(1,remain): c=(a+b)%m # or use just a+b a=b ...
d3b5a1d7defe60875420e63a92de521c1999f3b6
kampanella0o/python_basic
/lesson4/for.py
644
3.953125
4
########################################## # for item in 'hello': # print(item) ########################################### # a = ['red', 'green', 'blue'] # for color in a: # print(color) ###################################### # print("a" in "alalal") # print("a" in "hello") # print("a" in ['a', 'b', 'c']) # p...
138598c6e37b9b525b779902f4172f40e03ca3c2
kampanella0o/python_basic
/lesson4_home/l4_ex2.py
515
4.21875
4
n = '0' while int(n) <= 0: n = input("Please enter a natural number: ") try: int(n) except ValueError: print("You should enter a natural number!") n = '0' number_of_digits = len(n) if number_of_digits == 1: summ_of_digits = n else: while number_of_digits != 1: summ...
f8a43c6336dfde3c8d929454fb32640690b44e47
kampanella0o/python_basic
/lesson9/lambdas.py
444
3.796875
4
# func lambda x,y: x*y # def func(x,y): # return x*y #^^^^ same result for both # func = lambda x,y: x + y # result = func(1, None) # print(result) a = [1, 2, 3, 4, 5, 6] b = [2, 2, 2, 2, 3, 3] # result = list(map(str, a)) result = list(map(lambda x: x*2, a)) result1 = [x*2 for x in a] print(result1) print(...
8552d7e8b5821b056171871b615d5ba9459ee81a
kampanella0o/python_basic
/lesson5/l5_pr1.py
256
4.0625
4
string = input("Please, enter string: ") if len(string) > 5: new_string = string[0:3].upper() + string[3:] new_string = new_string[:-3] + new_string[-3:].lower() print(new_string) else: for i in string: print(string[0].swapcase())
3a18399d699248a6e85fbe96c6c853b5bacdd0ba
kampanella0o/python_basic
/lesson1/ifelse.py
1,001
4.1875
4
# name = "Da" # if name == "Max": # print(name) # else: # print('Its not Max') # a = 10 # b = 15 ############################################################ # if a == 10: # c = True # else: # if b == 10: # c = False # else: # c = True # c = True if a == 10 else False if b == 10...
cf3c88cf74d7f26207959aaa43329d8332c9a673
beanj25/Leap-year-program
/jacob_bean_hw1_error_handling.py
1,020
4.125
4
#------------------------------------------------------------------------------- # Name: module1 # Purpose: # # Author: Jacob # # Created: 15/01/2021 # Copyright: (c) Jacob 2021 # Licence: <your licence> #------------------------------------------------------------------------------- def...
a4643e01278f746cf516a10034151d993002be8d
abhi651/PYTHONLAB-II-B28-template---4
/binary_search.py
892
3.6875
4
""" write a program for Binary Search""" # It returns index of x in given array arr if present, # else returns -1 import unittest # Implement the below function and run this file # Return the output, No need read input or print the ouput def binary_search(lst,key): pass # DO NOT TOUCH THE BELOW CODE cla...
05ba6163fa9eed86e15032e479042fd2a1421842
VkaZas/cs1410
/Search/unit_tests.py
1,494
3.84375
4
import unittest from tilegameproblem import TileGame from search import bfs, dfs, ids, astar, bds, tilegame_heuristic class IOTest(unittest.TestCase): """ Tests IO for search implementations. Contains basic/trivial test cases. Each test function instantiates a search problem (TileGame) and tests if the t...
ffed2a436b881ab6681288237ae8000cbd669cc0
danielyu11765/qbb2016-answers
/day3-homework/day3-homework01.py
1,467
3.765625
4
#!/usr/bin/env python """ Read sequencne from a fasta file count the number of times each k-mer occurs across all sequences and print kmers and counts. usage: 01-kmer-counter.py k < fasta_file This is k-mer matcher """ import sys, fasta #from fasta import FASTAReader k = int(sys.argv[1]) for ident, sequence i...
a6693466af87a37897d2d438a53fa31b720d1877
nityakanuri/MyPythonWork
/isPrimeProblem.py
641
3.9375
4
# -*- coding: utf-8 -*- """ NOTES FOR Python Class 1 of 5 Created on Mon Aug 4 10:06:50 2014 @author: nityakanuri """ #print all primes from 0 to 1000 #for n in range(1,1001): # for i in range(2,n): # if (n % i == 0): # break # else: # print n # TO NOTE: This method did not work ...
7cc5443016abe0640631926ce77f1c28db78d61b
utsbansal/CGA-CSE-405N
/midpoint_circle.py
574
3.765625
4
import matplotlib.pyplot as plt def plot_symmetric_points(xc, yc, x, y): plt.plot(xc+x, yc+y, "ko") plt.plot(xc-x, yc+y, "ko") plt.plot(xc+x, yc-y, "ko") plt.plot(xc-x, yc-y, "ko") plt.plot(xc+y, yc+x, "ko") plt.plot(xc-y, yc+x, "ko") plt.plot(xc+y, yc-x, "ko") plt.plot(xc-y, yc-x, "ko") def midpoint(xc...
5a440871521bb6b9e105dbdd388bcb940ed947d0
mars2020/Bcycle-Project
/app/classes/google_api_client.py
1,230
3.515625
4
import requests from urllib.parse import urlencode class GoogleApiClient(object): lat = None lng = None api_key = None address = None data_type = 'json' reformatted_data = "" def __init__(self,api_key=None,address=None): self.api_key = api_key if self.api_key is None: ...
004ac43fd130f4774c04ff05c5c2d0bb3d275747
nandanv2702/Rock-Paper-Scissors
/RPS.py
775
4.03125
4
from random import randint probable_inputs = ["r", "p", "s"] def game(user): comp_input = probable_inputs[randint(0, 2)] print comp_input if user == comp_input: print "You guessed the same as the computer!" elif user == "r" and comp_input == "p": print "You lost!" elif user == "r" ...
a93dd1e770ce0e42feb4a51a3f0df7b3395abf8f
rodrigogomesrg/cursopython
/ex040.py
391
3.90625
4
nota1 = float(input('Nota 1: ')) nota2 = float(input('Nota 2: ')) media = (nota1 + nota2) / 2 if media <= 4.9: print(f'A média das notas foi: {media}') print('Aluno foi REPROVADO') elif 5.0 <= media <= 6.9: print(f'A média das notas foi: {media}') print('Aluno está em RECUPERAÇÃO') else: print(f'A ...
668ab3db86a3305568cd1ca45d2ec0da32c128e5
rodrigogomesrg/cursopython
/ex041.py
518
4.09375
4
from datetime import date anonasc = int(input('Informe o ano de nascimento: ')) idade = date.today().year - anonasc if idade <= 9: print(f'Sua idade é {idade} e sua categoria é MIRIM.') elif 10 <= idade <=14: print(f'Sua idade é {idade} e sua categoria é INFANTIL') elif 15 <= idade <= 19: print(f'Sua idad...
702b33ed83314d54ddaa6d55941de4d4255f85ff
rodrigogomesrg/cursopython
/ex058.py
400
3.921875
4
from random import randint computador = randint(0, 10) print('Acabei de pensar em um número.') counter = 0 while True: player = int(input('Tente advinhar qual foi: ')) counter += 1 if player > computador: print('Foi um número menor') elif player < computador: print('Foi um número maior'...
bd766195ea31e686853dfde53a79cf1db72cbea6
rodrigogomesrg/cursopython
/ex012.py
344
3.796875
4
valor = int(input('Digite o valor do produto: R$')) desconto = int(input('Desconto em %: ')) vdesconto = valor * desconto / 100 vfinal = valor - vdesconto print(f'Valor total do produto: R${valor:.2f}') print(f'Desconto de {desconto:.0f}%') print(f'Valor do desconto é de R${vdesconto:.2f}') print(f'Valor total a pagar ...
e24de96c67c5828a3b77252e8786feeeae6d74c2
rodrigogomesrg/cursopython
/ex010.py
209
3.5
4
carteira = float(input('Quanto de dinheiro você tem?: R$')) taxadolar = float(input('Taxa atual do dolar: R$')) conversor = carteira * taxadolar print(f'Com R${carteira:.2f} você compra US${conversor:.2f}')
b43d98d9d0cb7b868e88483e983bda27314752e2
rodrigogomesrg/cursopython
/ex030.py
173
4.09375
4
numero = int(input('Digite um número: ')) if numero % 2 == 0: print(f'O número é {numero} e ele é PAR.') else: print(f'O número é {numero} e ele é ÍMPAR.')
f3ae140615121ad88dc020fec73aabeaa754b139
rodrigogomesrg/cursopython
/ex054.py
421
3.859375
4
from datetime import date counterMaior = counterMenor = 0 for cadastro in range(0, 7): anoNascimento = int(input(f'Digite o ano de nascimento da {cadastro+1}º pessoa: ')) idade = date.today().year - anoNascimento if idade <= 17: counterMenor += 1 else: counterMaior += 1 print(f'Temos ao...
c50932f1f4574b690c3077f61c5b8590009d7a95
borsi/competitive-coding
/advent-of-code-2019/day1/modules.py
353
3.65625
4
import math def fuelReqs(mass): return (math.floor(mass / 3) - 2) def readData(datafile): with open(datafile) as f: return f.read().splitlines() def sumReqs(masses): sum = 0 for m in masses: sum += fuelReqs(int(m)) return sum def main(): masses = readData('input.txt') ...
888cc10705ee14a17690eb1b79e885cbf40772c9
borsi/competitive-coding
/advent-of-code-2020/3-1.2.py
626
3.734375
4
file = open("3-in.txt", "r") #file = open("3-intest.txt", "r") # lines = file.readlines() lines = file.read().splitlines() def is_tree(char): if (char == '#'): return True else: False slopes = [(1, 1), (3, 1), (5, 1), (7, 1), (1, 2)] def sloper(slope): right = slope[0] step = slope...
6a418fa8b303d64dfb60e430ab7f0244b43d0349
Bizcho/Curso-Python
/insert.py
117
3.546875
4
items = [4,6] print items items.insert(0, -1) #insertar en la posicion 0 print items items2 = [ ] print items2
1f7fb972d6202d7707c3a38c6741e2c4cb010719
rGitcy/LeetCode-Moving
/Array_test/read_value.py
153
3.828125
4
# read a element from array def value(nums, i): if 0 <= i <= len(nums)-1: print(nums[i]) # arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] value(arr, 5)
0c0712c2c5ecbe5e3fff554982d9996a54f34b07
kylehovey/card-shuffle-distances
/shuffle.py
3,728
3.6875
4
import random ''' See PDF of problem definition first. For convenience, decks are represented by ranges so that the absolute difference can be taken by subtracting each shuffled element from its index Ex: D = [ 0, 1, 2 ], D' = [ 2, 1, 0 ], <D, D'> = |2-0| + |1-1| + |0-2| = 4 ''' # D is a shuffled deck. The original...
7f73a2a6630338e6c98b4ea9537fd57e8cceeef5
fabianjmnz/List-Exercises
/Exercise_#6.py
108
3.546875
4
new_list= [] for number in range(-10,10): if number >0: new_list.append(number) print(new_list)
5cb3d8f7f94d2d0745a8807e8b9cd7542de59948
Ayesha116/piaic.assignment
/q6.py
189
4.625
5
#Write a Python program to get the volume of a sphere, please take the radius as input from user. V=4 / 3 πr3 r = int(input("enter radius: ")) print("area of sphere is: ",(4*3.142*r**3)/3)
af8097293d623675cee37791d5effd0fca7a33e8
Ayesha116/piaic.assignment
/q35.py
620
3.75
4
#Write a Python program to find the number of notes (Sample of notes: 10, 20, 50, 100, 500, and 1000 ) # variables used amount = 12680 count1000 = 0 count500 = 0 notesCountDict = { 1000: 0, 500: 0, 100: 0, 50: 0, 20: 0, 10: 0 } def notes_Counter(amnt, notes = {}): for k, v in notes.item...
e6400cd765f7f78747b1e2db375667d8c8f25a73
Ayesha116/piaic.assignment
/q12.py
233
4.09375
4
#Write a Python program that will accept the base and height of a triangle and compute the area h = int(input("enter height of triangle: ")) b = int(input("enter base of triangle: ")) area = h*b/2 print("area of triangle is ", area)
33b7628e6bdb51f4f146db155335768f3d873892
Ayesha116/piaic.assignment
/q19.py
340
4.28125
4
#Write a Python program to convert the distance (in feet) to inches, yards, and miles. 1 feet = 12 inches, 3 feet = 1 yard, 5280 feet = 1 mile feet = float(input("enter height in feet: ")) print(feet,"feet is equal to",feet*12, "inches ") print(feet, "feet is equal to",feet/3, "yards") print(feet, "feet is equal to",...
fc16f202293293de46ad8c76f8b5f3c65f69b21e
Ryan-Burgett/nn-first
/slope.py
453
3.921875
4
# coding: utf-8 # In[3]: def cost(b): return (b-4)**2 # In[4]: cost(0) # In[5]: def num_slope(b): h= 0.0001 return (cost(b+h)-cost(b))/h # In[7]: num_slope(3) # In[8]: def slope(b): return 2*(b-4) # In[9]: slope(3) # In[10]: slope(5) # In[11]: b = 8 # In[12]: b=b-.1*s...
24fa82c1bf23b2a01beeadd998d49a336cf3b1ef
theromis/mlpiper
/mlops/parallelm/mlops/stats_category.py
2,116
3.515625
4
from enum import Enum class StatCategory(Enum): """ Types of statistics classes that are supported when calling the MLOps.stat method. """ GENERAL = 0 #: Configuration value. When set multiple times, the last value will be kept. CONFIG = 1 #: Time series value. When set multiple times, ...
5bfcd4d69f89aebada93c2bb86db59c601f529c8
jabadia/advent-of-code-2019
/d24/d24p2.py
2,435
3.515625
4
from utils.test_case import TestCase INPUT = """ ####. .###. .#..# ##.## ###.. """ TEST_CASES = [ TestCase(""" ....# #..#. #.?## ..#.. #.... """, 99), ] def print_tiles(tiles): for level in range(-5, 6): print('level %d' % level) for row in range(5): for col in range(5): ...
98bd119dc7089046e77c26e4136e44c359359b81
susy2015/ZInvisible
/Tools/python/colors.py
1,799
3.6875
4
# colors.py import ROOT import json # xkcd color survey # see https://xkcd.com/color/rgb.txt # see https://xkcd.com/color/rgb/ # download text file using "wget https://xkcd.com/color/rgb.txt" # generate json file from the text file by running main() # print color, RGB, and index def printColors(): with open("rgb....
8b49d0aff9689bdd4a533f118287fd64aa426859
helloprogram6/leetcode_Cookbook_python
/Array/Array_search_74_240_81.py
3,089
3.796875
4
# -*- coding:utf-8 -*- # @FileName :Array_search.py # @Time :2021/4/6 15:18 # @Author :Haozr from typing import List import unittest # 解法1: class Solution: def searchMatrix74(self, matrix: List[List[int]], target: int) -> bool: """74. 搜索二维矩阵 行升序,每行的第一个整数大于前一行的最后一个整数 映射为一个升序数组,一次二分查找""" m ...
77e9c9fc62c1fb0834a457e2193a065448c0219c
helloprogram6/leetcode_Cookbook_python
/Offer/12_exist.py
1,093
3.875
4
# -*- coding:utf-8 -*- # @FileName :12_exist.py # @Time :2021/3/4 20:34 # @Author :Haozr from typing import List # 解法1: class Solution: def exist(self, board: List[List[str]], word: str) -> bool: m = len(board) n = len(board[0]) def dfs(i, j, s): if not 0 <= i < m or n...
3aa79b9bf7fe7a891899d632804b20c8ddff48c7
helloprogram6/leetcode_Cookbook_python
/DataStruct/BiTree/108_102_100_114.py
4,939
3.796875
4
# -*- coding:utf-8 -*- # @FileName :108_102_100_114.py # @Time :2021/3/17 18:24 # @Author :Haozr from typing import List class TreeNode: """二叉树结构""" def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right class Solution: def sort...
96f67acf3b9cae1727f5ae4737edb54ea4a5f6c1
helloprogram6/leetcode_Cookbook_python
/DataStruct/BiTree/字典树.py
1,390
4.21875
4
# -*- coding:utf-8 -*- # @FileName :字典树.py # @Time :2021/3/20 13:37 # @Author :Haozr from typing import List class TrieNode: def __init__(self, val=''): self.val = val self.child = {} self.isWord = False class Trie: def __init__(self): """ Initialize your data ...
49f3a1c42823b6b78e9ac8199aaff3bebb06a6cc
helloprogram6/leetcode_Cookbook_python
/Array/26_removeDuplicates.py
699
3.984375
4
# -*- coding:utf-8 -*- # @FileName :26_removeDuplicates.py # @Time :2020/12/23 21:22 # @Author :Haozr from typing import List # 解法1:数组去重,两个指针,将不重复的数移动到前面,直接覆盖不移动 class Solution: def removeDuplicates(self, nums: List[int]) -> int: length = len(nums) if length == 0: return 0 ...
7c1dfbbc1baf98904272f598608d04659b7b9053
jorzel/codefights
/arcade/python/competitiveEating.py
930
4.21875
4
""" The World Wide Competitive Eating tournament is going to be held in your town, and you're the one who is responsible for keeping track of time. For the great finale, a large billboard of the given width will be installed on the main square, where the time of possibly new world record will be shown. The track of ti...
72b951eebf3317d9a36822ef3056129257781ef1
jorzel/codefights
/challange/celsiusVsFahrenheit.py
1,549
4.4375
4
""" Medium Codewriting 2000 You're probably used to measuring temperature in Celsius degrees, but there's also a lesser known temperature scale called Fahrenheit, which is used in only 5 countries around the world. You can convert a Celsius temperature (C) to Fahrenheit (F), by using the following formula: F = 9 *...
658593501932b67c86b33a4f1a0ba2a1257e2de5
jorzel/codefights
/interview_practice/hash_tables/possibleSums.py
876
4.28125
4
""" You have a collection of coins, and you know the values of the coins and the quantity of each type of coin in it. You want to know how many distinct sums you can make from non-empty groupings of these coins. Example For coins = [10, 50, 100] and quantity = [1, 2, 1], the output should be possibleSums(coins, quant...
a895f944d16973c807f69842df735e89eb0f0b21
jorzel/codefights
/arcade/python/convertTabs.py
760
4.03125
4
""" You found an awesome customizable Python IDE that has almost everything you'd like to see in your working environment. However, after a couple days of coding you discover that there is one important feature that this IDE lacks: it cannot convert tabs to spaces. Luckily, the IDE is easily customizable, so you decide...
fa6b0a7a6ffc4673209ebb9b6c8b727ffe343f4f
jorzel/codefights
/arcade/core/houseOfCats.py
806
4.03125
4
""" There are some people and cats in a house. You are given the number of legs they have all together. Your task is to return an array containing every possible number of people that could be in the house sorted in ascending order. It's guaranteed that each person has 2 legs and each cat has 4 legs. Example For legs...
4193ada270f7accddd799997c1c705545eb243f3
jorzel/codefights
/arcade/core/isCaseInsensitivePalindrome.py
742
4.375
4
""" Given a string, check if it can become a palindrome through a case change of some (possibly, none) letters. Example For inputString = "AaBaa", the output should be isCaseInsensitivePalindrome(inputString) = true. "aabaa" is a palindrome as well as "AABAA", "aaBaa", etc. For inputString = "abac", the output shou...
495f3051e8737856cf1adbc0dbd601166b185ec5
jorzel/codefights
/arcade/intro/evenDigitsOnly.py
346
4.25
4
""" Check if all digits of the given integer are even. Example For n = 248622, the output should be evenDigitsOnly(n) = true; For n = 642386, the output should be evenDigitsOnly(n) = false. """ def evenDigitsOnly(n): el_list = [int(i) for i in str(n)] for p in el_list: if p % 2 != 0: ret...
051faa94e67dcb9db8c35ec2bb577d8fb0598c32
jorzel/codefights
/arcade/intro/growingPlant.py
704
4.625
5
""" Each day a plant is growing by upSpeed meters. Each night that plant's height decreases by downSpeed meters due to the lack of sun heat. Initially, plant is 0 meters tall. We plant the seed at the beginning of a day. We want to know when the height of the plant will reach a certain level. Example For upSpeed = 10...
dd6eaf240e1c6c3c75a28d7a0bef4c6cefc81192
jorzel/codefights
/arcade/core/createArray.py
215
3.625
4
""" Given an integer size, return array of length size filled with 1s. Example For size = 4, the output should be createArray(size) = [1, 1, 1, 1]. """ def createArray(size): return [1 for s in range(size)]
793d7f40b44fb4753b4be6e2569c26c40c70dc44
jorzel/codefights
/arcade/core/arrayPreviousLess.py
771
3.84375
4
""" Given array of integers, for each position i, search among the previous positions for the last (from the left) position that contains a smaller value. Store this value at position i in the answer. If no such value can be found, store -1 instead. Example For items = [3, 5, 2, 4, 5], the output should be arrayPrevi...
455f2a51259a5c06c167a5c6560cf0a22e4f2ce3
jorzel/codefights
/arcade/python/tryFunctions.py
1,035
4.125
4
""" Easy Recovery 100 Implement the missing code, denoted by ellipses. You may not modify the pre-existing code. You've been working on a numerical analysis when something went horribly wrong: your solution returned completely unexpected results. It looks like you apply a wrong function at some point of calculation....
ce48cbba7f958528e805274f3ed4a8627c584d6b
jorzel/codefights
/interview_practice/linked_lists/removeKFromList.py
825
4
4
""" Given a singly linked list of integers l and an integer k, remove all elements from list l that have a value equal to k. Example For l = [3, 1, 2, 3, 4, 5] and k = 3, the output should be removeKFromList(l, k) = [1, 2, 4, 5]; For l = [1, 2, 3, 4, 5, 6, 7] and k = 10, the output should be removeKFromList(l, k) = [...
94c2397a4ecb9cbfbe88f8b5c7831805fc246562
jorzel/codefights
/interview_practice/arrays/rotateImage.py
471
4.46875
4
""" Note: Try to solve this task in-place (with O(1) additional memory), since this is what you'll be asked to do during an interview. You are given an n x n 2D matrix that represents an image. Rotate the image by 90 degrees (clockwise). Example For a = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] the output should ...
fbd4547ed66da342fd6455255c60be3b2cc311b9
jorzel/codefights
/arcade/python/checkParticipants.py
1,018
3.578125
4
""" Implement the missing code, denoted by ellipses. You may not modify the pre-existing code. You're organizing murder mystery games for your coworkers, and came up with a lot of ideas for various groups of participants. The ith 0-based game can be played only if there are at least i people registered for it. Game num...
79adde61099687ec340632cb4f4d88f65934c998
jorzel/codefights
/interview_practice/common_techinques_basic/sumInRange.py
869
3.609375
4
""" You have an array of integers nums and an array queries, where queries[i] is a pair of indices (0-based). Find the sum of the elements in nums from the indices at queries[i][0] to queries[i][1] (inclusive) for each query, then add all of the sums for all the queries together. Return that number modulo 109 + 7. Exa...
bf478f57a92292130d80797078db8833a312eb68
jorzel/codefights
/interview_practice/heaps_stacks_queues/kthLargestElement.py
696
4.09375
4
""" Note: Avoid using built-in std::nth_element (or analogous built-in functions in languages other than C++) when solving this challenge. Implement them yourself, since this is what you would be asked to do during a real interview. Find the kth largest element in an unsorted array. This will be the kth largest elemen...
7757551f8a04e9875fd09f7cce05b1a06aafab49
jorzel/codefights
/arcade/intro/longestDigitsPrefix.py
439
4.15625
4
""" Given a string, output its longest prefix which contains only digits. Example For inputString="123aa1", the output should be longestDigitsPrefix(inputString) = "123". """ def longestDigitsPrefix(inputString): max_seq = "" for i, el in enumerate(inputString): if i == 0 and not el.isdigit(): ...
ba4e27a6d30f4d77ddb936e82e44e4c35913a29a
jorzel/codefights
/arcade/core/rowRearranging.py
696
4
4
""" Medium Codewriting 300 Given a rectangular matrix of integers, check if it is possible to rearrange its rows in such a way that all its columns become strictly increasing sequences (read from top to bottom). Example For matrix = [[2, 7, 1], [0, 2, 0], [1, 3, 1]] the output should be rows...
bfc993bfda53b5a1e69f4b1feefc9b0eea4bdb22
jorzel/codefights
/arcade/core/concatenateArrays.py
282
4.15625
4
""" Given two arrays of integers a and b, obtain the array formed by the elements of a followed by the elements of b. Example For a = [2, 2, 1] and b = [10, 11], the output should be concatenateArrays(a, b) = [2, 2, 1, 10, 11]. """ def concatenateArrays(a, b): return a + b
cc9e43e94fd96b2407b289ef20cf5a7c04652c3d
jorzel/codefights
/interview_practice/strings/findFirstSubstringOccurence.py
751
4.3125
4
""" Avoid using built-in functions to solve this challenge. Implement them yourself, since this is what you would be asked to do during a real interview. Implement a function that takes two strings, s and x, as arguments and finds the first occurrence of the string x in s. The function should return an integer indicat...
cdafbefb476869fa4d3d817bd39f122488bbda64
jorzel/codefights
/challange/zeroProfitPeriod.py
1,246
3.65625
4
""" Lindsey, a small fox, has a bank account. She has a list of her transactions during some period of time. Negative transactions[i] means that the money leaves the account, and positive transactions[i] means that money is added to the account. Lindsey refers to the sum of consecutive transactions as the profit of th...
d5fb5c2f5e7edc4f7c511e4bdc8a3d5b60a1657e
jorzel/codefights
/arcade/python/crazyball.py
1,290
3.734375
4
""" Easy Recovery 100 Implement the missing code, denoted by ellipses. You may not modify the pre-existing code. You've been training your whole life, and now your dreams finally came true: you are a member of the best Crazyball team in the world! Unfortunately since your team is one of only two teams that play Craz...
4538d33c52315bdffa467cc75213a257466a8792
jorzel/codefights
/arcade/intro/addBorder.py
603
4.09375
4
""" Given a rectangular matrix of characters, add a border of asterisks(*) to it. Example For picture = ["abc", "ded"] the output should be addBorder(picture) = ["*****", "*abc*", "*ded*", "*****"] """ def addBorder(picture): bordere...
df6930a4776a2e67381065e5dbfc8d5dfe64bf03
jorzel/codefights
/arcade/python/isWordPalindrome.py
374
4.625
5
""" Given a word, check whether it is a palindrome or not. A string is considered to be a palindrome if it reads the same in both directions. Example For word = "aibohphobia", the output should be isWordPalindrome(word) = true; For word = "hehehehehe", the output should be isWordPalindrome(word) = false. """ def i...
7d45a1763daba19092f1bf90be848ac9053d727b
jorzel/codefights
/bots/mzbot/resourceCatchUp.py
1,512
4.03125
4
""" Medium Codewriting 1000 As part of a successful war campaign you just took control of a major city. This is where you will make your new Forward Operating Base, and where your troops will house their new barracks. However, when your troops are in the city they consume k units of food (for some integer k) as upke...