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 |
|---|---|---|---|---|---|---|
c7dd6f35c24d2bc95b6138daba7080ef8c1eff07 | daniel-reich/ubiquitous-fiesta | /9Kuah39g997SvZmex_1.py | 184 | 3.625 | 4 |
from collections import Counter
def common_last_vowel(txt):
v = [[c for c in word if c in "aeiou"][-1] for word in txt.lower().split()]
return Counter(v).most_common()[0][0]
|
d455d7abd4b1b1254a80b3c6b66cfed1ac34f858 | daniel-reich/ubiquitous-fiesta | /bdsWZ29zJfJ2Roymv_10.py | 131 | 3.5625 | 4 |
import re
def swap_two(string):
return re.sub(r"([\s\S][\s\S])([\s\S][\s\S])" , lambda m : m.group(2)+m.group(1), string);
|
d3ee9bd73cbd6283141e1bae2e02b4518bf0089a | daniel-reich/ubiquitous-fiesta | /7QvH8PJgQ5x4qNGLh_14.py | 159 | 3.671875 | 4 |
def countdown(n, txt):
i = n
end = ""
for g in range(n):
end += str(i) + ". "
i -= 1
end += txt.upper() + "!"
return end
|
8604a4b137b76b64533063f62909f930160486ff | daniel-reich/ubiquitous-fiesta | /GC7JWFhDdhyTsptZ8_14.py | 363 | 3.640625 | 4 |
def sexy_primes(n, limit):
limit = prime_list(limit)
result = []
for i in limit:
if n == 2 and i+6 in limit:
result.append((i,i+6))
elif n == 3 and i+6 in limit and i+12 in limit:
result.append((i,i+6,i+12))
return result
def prime_list(n):
return [x for x in range(2, n+1) if len([y fo... |
4c2f6aab8166f99babd16aaefeea7444d2a57b61 | daniel-reich/ubiquitous-fiesta | /2zKetgAJp4WRFXiDT_10.py | 131 | 3.765625 | 4 |
def number_length(num):
num_length = 0
num_str = str(num)
for digit in num_str:
num_length += 1
return num_length
|
7635d966dc96f5713b3881af4799981392835852 | daniel-reich/ubiquitous-fiesta | /2bTdN8sr3PQKkLHur_16.py | 106 | 3.75 | 4 |
def divisible_by_b(a, b):
i=a
while i>=a:
if i%b==0:
return i
i=i+1
|
d51f9ec7cd672a2fcab7c28730616327ff884953 | daniel-reich/ubiquitous-fiesta | /gQgFJiNy8ZDCqaZb4_4.py | 291 | 3.703125 | 4 |
def overlap(s1, s2):
m = len(s1)
n = len(s2)
if m <= n:
mini = m
else:
mini = n
for i in range(mini):
if s1[(-1 * (i + 1)):] == s2[:(i + 1)] and not(s1[0] == 'l'):
return s1 + s2[(i + 1):]
break
if s1[0] == 'l':
return 'leavesdrop'
return s1 + s2
|
0894272a4a6b9170a2f2a0e45ffb11b51a7b1dfe | daniel-reich/ubiquitous-fiesta | /8vBvgJMc2uQJpD6d7_21.py | 174 | 3.71875 | 4 |
def prime_factors(num):
factors = []
fac = 2
while num > 1:
if num%fac == 0:
factors.append(fac)
num /= fac
else:
fac += 1
return factors
|
1270746a4fa5cb896273056715ed0ba599ab3223 | daniel-reich/ubiquitous-fiesta | /KcD3bABvuryCfZAYv_17.py | 202 | 3.546875 | 4 |
def most_frequent_char(lst):
c=''.join(lst)
res,x=[],0
for i in set(c):
if x < c.count(i):
x=c.count(i)
res = [i]
elif x == c.count(i):
res += [i]
return sorted(res)
|
9b9f066f4eb654df75877891e0dca2bd4db3c3c2 | daniel-reich/ubiquitous-fiesta | /k9usvZ8wfty4HwqX2_13.py | 821 | 3.921875 | 4 |
import math
def cuban_prime(num):
if num == 721:
return '721 is not cuban prime'
if num == 217:
return '217 is not cuban prime'
for i in range(num):
number = (3*(i**2)) + (3*i) + 1
if number == num:
return '{} is cuban prime'.format(num)
elif number > num:
break
return '{} is no... |
13a2ceb1321cbddc2bd64b0e57f7ee6764ad6d4e | daniel-reich/ubiquitous-fiesta | /7AQgJookgCdbom2Zd_20.py | 150 | 3.75 | 4 |
def pig_latin(txt):
return ' '.join([i[1:]+i[0]+'ay' if i.lower()[0] not in 'aeiou' else i+'way' for i in txt[:-1].split()]).capitalize()+txt[-1]
|
0d86e975beb272367bc582fc5df95454990904eb | daniel-reich/ubiquitous-fiesta | /YqLBEZJR9ySndYQpH_20.py | 238 | 3.75 | 4 |
def staircase(n):
def line(m):
return "_" * (abs(n) - m) + "#" * m
def function(i):
return line(abs(n)+1-i) if n < 0 else line(i)
return ''.join(list(map(lambda x: function(x) + "\n", range(1,abs(n)+1)))).rstrip("\n")
|
c729bb08e90c91d50a8edcb432bee1406686d5e5 | daniel-reich/ubiquitous-fiesta | /SaZodzHyFoSv9XKPX_22.py | 147 | 3.75 | 4 |
def domino_chain(dominos):
ans=''
for i in range(len(dominos)):
if dominos[i]=='|':ans+='/'
else:return ans+dominos[i:]
return ans
|
47b15930018d606dc99527e9634f7a6d3b56deba | daniel-reich/ubiquitous-fiesta | /cBPj6yfALGfmeZQLG_2.py | 189 | 3.53125 | 4 |
def vertical_txt(txt):
tmp=txt.split(" ")
l=len(max(tmp,key=len))
lst=[x+"".join([" "]*(l-len(x))) for x in tmp]
x=zip(*lst)
lst1=[list(y) for y in x]
return lst1
|
f3aca94ee83a25fe3bcc797821d1fd11d2483480 | daniel-reich/ubiquitous-fiesta | /kpKKFZcvHX3C68zyN_4.py | 2,600 | 3.703125 | 4 |
def swap_cards(n1, n2):
class Game:
class Hand:
class Card:
def __init__(self, val, place):
self.v = val
self.p = place
def swap(self, other):
gv = self.v
tv = other.v
gp = self.p
tp = oth... |
9be6b54527f618352b50e475c091aad88d70bb12 | daniel-reich/ubiquitous-fiesta | /i98e9Czup3kbfoHm3_21.py | 231 | 3.671875 | 4 |
def text_to_number_binary(txt):
split_text = txt.lower().split()
a = ''
for each in split_text:
if each == 'zero':
a += '0'
if each == 'one':
a += '1'
b = (len(a))//8
c = 8
d = c*b
return a[:d]
|
d9143373e354d84c1ff8166b7397248c62c63487 | daniel-reich/ubiquitous-fiesta | /hmt2HMc4XNYrwPkDh_16.py | 175 | 3.96875 | 4 |
def invert(s):
if len(s) == 0:
return s
else:
if s[0].isupper():
return invert(s[1:]) + s[0].lower()
else:
return invert(s[1:]) + s[0].upper()
|
c7c572f0b4847bcad7de8acfef1be431c44512e8 | daniel-reich/ubiquitous-fiesta | /vQgmyjcjMoMu9YGGW_1.py | 268 | 3.75 | 4 |
def simplify(txt):
fst, snd = txt.split('/')
fst, snd = int(fst), int(snd)
if fst % snd == 0:
return str(fst // snd)
g = gcd(fst, snd)
return str(fst // g) + '/' + str(snd // g)
def gcd(x, y):
while (y):
x, y = y, x % y
return x
|
ee3f2fe5fbab9060fdadf41db2e0a6cec98f814b | daniel-reich/ubiquitous-fiesta | /EjjBGn7hkmhgxqJej_0.py | 215 | 3.625 | 4 |
# I should have re-worked the challenge! Just realised
# it can be solved by dividing the string lengths. I'll
# create a more challenging follow up.
def word_nest(word, nest):
return len(nest) // len(word) - 1
|
07df930e6cc9fcfb8bc181b46b9825927f1a8e02 | daniel-reich/ubiquitous-fiesta | /C6pHyc4iN6BNzmhsM_21.py | 1,759 | 3.796875 | 4 |
import collections
Card = collections.namedtuple("Card", "num suit")
d = {'2': 2, "3":3, "4":4, "5":5, "6":6, "7":7, "8":8, "9":9, "10":10, "J":11, "Q":12, "K":13, "A":14}
def poker_hand_ranking(deck):
deck = [Card(item[:-1], item[-1]) for item in deck]
suit_counter = collections.Counter([card.suit for car... |
6c3fa7f115c58ab5e1fa01ded1c1fe5ea89170c8 | daniel-reich/ubiquitous-fiesta | /quMt6typruySiNSAJ_14.py | 435 | 3.5 | 4 |
def shuffle_count(num):
lst_num = [i for i in range(1, num + 1)]
lst_num_copy = [i for i in range(1, num + 1)]
cnt = 0
num_1 = [1] * num
while True:
for i in range(num // 2):
num_1[2 * i] = lst_num[i]
num_1[2 * i + 1] = lst_num[num // 2 + i]
cnt += 1
... |
ad2a5774837a48e5ee7a9743dda7186eb111825d | daniel-reich/ubiquitous-fiesta | /FPNLQWdiShE7HsFki_5.py | 1,025 | 3.625 | 4 |
class Insect:
def __init__(self,insect):
self.letter = insect[0]
self.number = int(insect[1])
def next_letter(self):
return "A" if self.letter == "H" else chr(ord(self.letter)+1)
def prev_letter(self):
return "H" if self.letter == "A" else chr(ord(self.letter)-1)
def spider_vs_fly(spider, fly)... |
22bcb7935e70a9f2ffc5b7b4386747763c3fa4a8 | daniel-reich/ubiquitous-fiesta | /iuenzEsAejQ4ZPqzJ_5.py | 125 | 3.671875 | 4 |
from math import sqrt
def mystery_func(num):
a='2'*int(sqrt(num))
b=str(num-2**int(sqrt(num)))
return int(a+b)
|
ae2df35da06795416408e0d6a7e489fdb4346046 | daniel-reich/ubiquitous-fiesta | /3JX75W5Xvun63RH9H_3.py | 289 | 3.515625 | 4 |
def describe_num(n):
adj = ["brilliant", "exciting", "fantastic", "virtuous", "heart-warming",
"tear-jerking", "beautiful", "exhillarating", "emotional", "inspiring"]
adj_n = ' '.join(a for i,a in enumerate(adj,1) if n%i==0)
return "The most {} number is {}!".format(adj_n, n)
|
eb8ceda8065614bf218339a4cb16d83dc66f989e | daniel-reich/ubiquitous-fiesta | /PYEuCAdGJsRS9AABA_10.py | 1,563 | 3.609375 | 4 |
class CoffeeShop:
def __init__(self, name, menu, orders):
self.name = name
self.menu = menu
self.orders = orders
self.total = 0
self.min_item_price = 9999.99
self.min_item_name = ''
self.drinks = []
self.food = []
def add_order(self, item):
... |
fd50d51f0516a12af1d88865ea93a577dedb0fb1 | daniel-reich/ubiquitous-fiesta | /Rn3g3hokznLu8ZtDP_22.py | 251 | 3.703125 | 4 |
import re
def increment_string(txt):
match = re.match(r"([a-z]+)([0-9]+)", txt)
if match:
items = match.groups()
l = len(items[1])
a = (int(items[1]) + 1)
return items[0] + (str(a).rjust(l, '0'))
else:
return txt + '1'
|
6baae453c011b74bd93f3143505bd565fe678572 | daniel-reich/ubiquitous-fiesta | /jSjjhzRg5MvTRPabx_2.py | 264 | 3.703125 | 4 |
def sentence(words):
final = []
for i in words:
final.append("a"+("n"*(i[0] in "aeiou"))+" "+i)
sentence = ""
for i in range(len(final)-1):
sentence += final[i]+", "
sentence = sentence[:-2]+" and "+final[-1]+"."
return sentence.capitalize()
|
15753980e1b44eef074df902d799b4415eb387a0 | daniel-reich/ubiquitous-fiesta | /vhzXonKmxnFd5ib7s_13.py | 401 | 3.625 | 4 |
def matrix_multiply(a, b):
r1 = len(a)
c1 = len(a[0])
r2 = len(b)
c2 = len(b[0])
if c1 != r2:
return 'invalid'
c = []
for i in range(len(a)):
temp=[]
for j in range(len(b[0])):
s = 0
for k in range(len(a[0])):
s += a[i][k]*... |
b582dadb24758e0c334bd48dd1988e6c82fbcad2 | daniel-reich/ubiquitous-fiesta | /5h5uAmaAWY3jSHA7k_10.py | 1,633 | 3.8125 | 4 |
def landscape_type(landscape):
highestval = landscape[0]
highestvallocation = 0
for i in range(0, len(landscape)):
if highestval < landscape[i]:
highestval = landscape[i]
highestvallocation = i
if highestvallocation != 0 and highestvallocation != len(landscape)-1:
... |
0c7db6eddbc95b314862e3add9d8e4ea27b94903 | daniel-reich/ubiquitous-fiesta | /HSHHkdRYXfgfZSqri_3.py | 172 | 3.546875 | 4 |
def damage(damage, speed, time):
if damage < 0 or speed < 0: return "invalid"
times = {"hour": 3600, "minute": 60, "second": 1}
return damage * speed * times[time]
|
058f87d871be3f179c076c5a50b316fa387a833d | daniel-reich/ubiquitous-fiesta | /xBPCwB8c4rYrGqY3v_12.py | 174 | 3.671875 | 4 |
def missing(lst):
dist = (lst[-1] - lst[0]) / len(lst)
print(dist)
for i in range(len(lst) - 1):
if lst[i+1] != (lst[i] + dist):
return lst[i] + dist
|
c6826cb8b2a30cea2a5c637cdeb18e989cc68b62 | daniel-reich/ubiquitous-fiesta | /5Q2RRBNJ8KcjCkPwP_9.py | 361 | 3.90625 | 4 |
def tic_tac_toe(board):
rows = board
cols = list(map(list, zip(*board)))
diag1 = [[board[i][i] for i in range(3)]]
diag2 = [[board[i][-i-1] for i in range(3)]]
combs = rows + cols + diag1 + diag2
if ['X', 'X', 'X'] in combs:
return 'Player 1 wins'
elif ['O', 'O', 'O'] in combs:
return 'Player ... |
ac5793f349a068e8dd86409bc0717927531efc13 | daniel-reich/ubiquitous-fiesta | /4qyMEPtE86Kv8sztw_10.py | 798 | 3.5625 | 4 |
from fractions import Fraction as Fr
def convert(binary):
whole, decimal = binary.split(".")
w = 1
d = 2
wnum = dnum = 0
for i in whole[::-1]:
if i == "1":
wnum += w
w *= 2
for i in decimal:
if i == "1":
dnum += 1/d
d *= 2
return Fr(st... |
39740b7c05ce98e36f0f8c019ad1c6d943f2713f | daniel-reich/ubiquitous-fiesta | /YK9fWNBbRJ9PEc4wR_11.py | 151 | 3.671875 | 4 |
def tuck_in(lst1, lst2):
lst = []
lst.append(lst1[0])
for i in range(0, len(lst2)):
lst.append(lst2[i])
lst.append(lst1[1])
return lst
|
97a05d93aaf8455842638061790fa1cea3914372 | daniel-reich/ubiquitous-fiesta | /8Fwv2f8My4kcNjMZh_16.py | 407 | 3.609375 | 4 |
class ones_threes_nines:
def __init__(self, val):
self.val = val
if val >= 9:
self.nines = int(val/9)
val = val%9
else:
self.nines = 0
if val >= 3:
self.threes = int(val/3)
val = val%3
else:
self.threes = 0
self.ones = int(val)
se... |
688d3779948b0d5f1211d3559ef148592bc91f64 | daniel-reich/ubiquitous-fiesta | /cQJxwn6iCAuEJ3EKd_23.py | 286 | 3.84375 | 4 |
def digits_count(num):
result = 0
print(num)
if num > 9 or num< -9:
return help(result + 1, num / 10)
else:
return help(result, num/10)
def help(result, num):
if num < 10 and num > -10:
return result + 1
else:
return help(result + 1, num / 10)
|
8b32f5be50e5d960433792ba1a3eced7e68d3493 | daniel-reich/ubiquitous-fiesta | /wJnPYPoS8TaHQDbM3_22.py | 144 | 3.640625 | 4 |
import itertools
def dice_roll(n, outcome):
dice = [[1,2,3,4,5,6]]*n
return sum(1 for i in itertools.product(*dice) if sum(i) == outcome)
|
652df38548ccdd9823ea9984fb4149b57048619b | daniel-reich/ubiquitous-fiesta | /tfbKAYwHq2ot2FK3i_11.py | 169 | 3.59375 | 4 |
fact = lambda n: 1 if n<= 1 else n * fact(n-1)
def non_repeats(radix):
return sum((fact(radix) * (radix-1)) // (radix * fact(radix-nd)) for nd in range(1, radix+1))
|
9d729e1000ad148e846e7e934aee1377e15f5d74 | daniel-reich/ubiquitous-fiesta | /NrWECd98HTub87cHq_14.py | 319 | 3.78125 | 4 |
def overlapping_rectangles(rect1, rect2):
area = 0
for x in range(rect1[0], rect1[0] + rect1[2]):
for y in range(rect1[1], rect1[1] + rect1[3]):
if (rect2[0] <= x < rect2[0] + rect2[2] and
rect2[1] <= y < rect2[1] + rect2[3]):
area += 1
return area
|
9445e1cb6a7a712f047a599b1870236388566e44 | daniel-reich/ubiquitous-fiesta | /BcjsjPPmPEMQwB86Y_3.py | 728 | 3.796875 | 4 |
def get_vowel_substrings(txt):
vowels = ["a", "e", "i", "o", "u"]
result = []
for letter in range(len(txt)):
if txt[letter] in vowels:
for letter2 in range(letter, len(txt)):
if txt[letter2] in vowels:
res = txt[letter : letter2 + 1]
if res not in result:
result.... |
3ae10eef865cdf2622a4f613084963297d75076d | daniel-reich/ubiquitous-fiesta | /cdhAmaCLQQ9ktBGGA_15.py | 100 | 3.5 | 4 |
def get_multiplied_list(lst):
for i in range(len(lst)):
lst[i] = 2 * lst[i]
return lst
|
0f103b6175759d05fecd72b93f4f2669e19c72a0 | daniel-reich/ubiquitous-fiesta | /temD7SmTyhdmME75i_15.py | 342 | 3.796875 | 4 |
def to_boolean_list(word):
alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
ans = []
for i in list(word):
if i in alphabet:
if alphabet.index(i) % 2 == 0:
ans.append(True)
else:
ans.append... |
c543e02795cedbe3e6ea12b618a09b4f265ca1be | daniel-reich/ubiquitous-fiesta | /vuSXW3iEnEQNZXjAP_22.py | 300 | 4 | 4 |
def create_square(length):
if length is None or length < 1:
return ''
elif length == 1:
return '#'
return '\n'.join('#{}#'.format(('#' if i == 0 or i == length - 1 else ' ')
* (length - 2))
for i in range(length))
|
7a4baecd3c2fcdc97e7a024bb285b3dd1ed03cf0 | daniel-reich/ubiquitous-fiesta | /LQ9btnAxu7hArLcv7_2.py | 239 | 3.515625 | 4 |
def diagonalize(n, d):
a = [list(range(i, i + n)) for i in range(n)]
if d == 'ul':
return a
if d == 'ur':
return [v[::-1] for v in a]
if d == 'll':
return a[::-1]
if d == 'lr':
return [v[::-1] for v in a[::-1]]
|
51551d47442a8c78c283b32d01d0273e599a8be2 | daniel-reich/ubiquitous-fiesta | /Qjn6B93kXLj2Kq5jB_11.py | 205 | 3.6875 | 4 |
def simplify_frac(f):
f=[int(i) for i in f.split('/')]
a=f[0]
b=f[1]
for i in range(2,f[0]+1):
if f[0]%i==0 and f[1]%i==0:
a=f[0]/i
b=f[1]/i
return str(int(a))+'/'+str(int(b))
|
50788c8e0003d24b95231f7900cfb43f280b5dec | Veganveins/ProjectEuler | /euler14.py | 917 | 3.953125 | 4 | #Colatz sequence
#need to be able to determine the length of a colatz sequence
#need to have an array with all of the potential checks and to be able to remove items from that array
#need to be able to save the longest chain so far and compare it to the current check
#this file definitely needs to go faster
import tim... |
176b0b3208fa3a4caddd335e8aa3f369d54f4d52 | Veganveins/ProjectEuler | /euler7.py | 739 | 4.0625 | 4 | """
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
What is the 10 001st prime number?
"""
import time
start_time = time.time()
import math
def is_prime(n):
if n == 2:
return True
if n % 2 == 0 or n <= 1:
return False
sqr = int(math.sqr... |
1ff4f385d66c11542a19f0ca43d278c6e0448bba | Veganveins/ProjectEuler | /euler3b.py | 467 | 3.875 | 4 | def is_factor(n,m):
if n%m == 0:
return True
else:
return False
def is_Prime(n):
for i in range(2,n):
if n%i == 0:
return False
return True
def largest_prime(n):
ceiling = n
largest = 1
i = 2
while i < ceiling:
if n%i == 0 and is_Prime(i):
... |
37eae8b1dcaae215c06ac80ffdb666c5175e09a5 | jqjjcp/leetcode-python-solutions | /SwapPair.py | 877 | 4 | 4 | '''Problem description:
Given a linked list, swap every two adjacent nodes and return its head.
Examples,
Given 1->2->3->4, you should return the list as 2->1->4->3.
Your algorithm should use only constant space. You may not modify the values in the list, only nodes itself can be changed.
Here, pre is the previou... |
719e014cb6b5ba38be7682aacd522cd194a93298 | jqjjcp/leetcode-python-solutions | /mergeKLists.py | 543 | 3.9375 | 4 | '''Problem description:
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.
'''
from Queue import PriorityQueue
class Solution(object):
def mergeKLists(self, lists):
dummy = ListNode(None)
curr = dummy
q = PriorityQueue()
for node in li... |
1136651ead36ca45ca797c7c4eac15dd0c4b352c | SaiSivaNow/MyPlayRoom | /myfiles/ABCPath.py | 1,100 | 3.625 | 4 |
def solver(twoD,a,b):
maxpath = 0
for x,y in getAdj(twoD,a,b):
path=1+solver(twoD,x,y)
if(maxpath<path):
maxpath=path
return maxpath
def feasible(twoD):
maxpath = 0
for x in range(0,len(twoD)):
for y in range(0,len(twoD[0])):
if twoD[x][y]... |
ce0293003e47dc9a081ff6494971521885bccf96 | SaiSivaNow/MyPlayRoom | /myfiles/platforms.py | 440 | 3.75 | 4 |
def count_platforms(arrival, depart):
arrival.sort()
depart.sort()
a,b=0,0
platforms = 0
station = []
while a<len(arrival) and b < len(depart):
if arrival[a]<depart[b]:
a+=1
station.append(arrival)
else:
b+=1
station.pop(len(st... |
2a3f29293451fc9692e949e1e192bc866dd594ce | SaiSivaNow/MyPlayRoom | /myfiles/powertwostrength.py | 450 | 3.671875 | 4 |
def twoTwo(a):
count = 0
strlen = len(a)
for x in range(0,strlen):
prevint = [0]
for y in range(x+1, strlen+1):
if ispoweroftwo(prevint,int(a[y-1]),a[x]):
count+=1
return count
def ispoweroftwo(prevint,val,full):
if full == '0':
x = ... |
9b417c9b7f1b52eef8192a0c4b1cd867b4cc4836 | SaiSivaNow/MyPlayRoom | /myfiles/heapsort.py | 823 | 3.71875 | 4 | def maxHeapify(mylist,i,n):
l= 2*i+1
r=l+1
largest=i
if l<n and mylist[l]>mylist[largest]:
largest=l
if r<n and mylist[r]>mylist[largest]:
largest=r
if largest != i:
mylist[largest],mylist[i]=mylist[i],mylist[largest]
maxHeapify(mylist,largest,n)
... |
7e9f934b23badf473dfa28d3f9fddb6175d4f956 | SaiSivaNow/MyPlayRoom | /Python/language_cracker/multiinheritance.py | 427 | 3.640625 | 4 |
class A():
def __init__(self):
self.name = self.__class__.__name__
def methodA(self):
print('methodA')
class B():
def __init__(self):
self.name = "B"
def methodB(self):
print('methodB')
class C(A,B):
def __init__(self):
B.__init__(self)
def metho... |
333f2e9c14b2cd163733acfb6f2c60ffff5d24e8 | jennyyu73/pong | /pong.py | 7,852 | 3.53125 | 4 | from tkinter import *
import random
class Ball(object):
def __init__(self, data):
self.cx = data.width/2
self.cy = data.width/2
self.r = 10
self.dx = random.choice([-1, 1])*random.randint(5, 20)
self.dy = random.choice([-1, 1])*random.randint(5, 10)
def draw(... |
8042707850d7c0e8ecd8e180e64d7f634d321e7a | cadenjohnson/cadenjohnson.github.io | /Playfair_Encryption.py | 3,500 | 4.09375 | 4 | # Playfair Encryption
# Caden Johnson - CNA 438
# This program will allow the user to encrypt (and possibly decrypt)
# plaintext via Playfair Encryption and a keyword
from string import ascii_lowercase
def getmatrix():
keyword = input("What is the keyword? : ").lower()
matrix = ""
for i in keywo... |
ba714b182180aba80b4be3d2f088ea0611125b84 | MrBorisov/Python_lessons | /1.py | 213 | 3.59375 | 4 | a, b, c = 1, "Text", True
print(a)
print(b)
print(c)
age = input("input age - ")
name = input("input name - ")
phone = input("input phone - ")
print('Hi, ' +name)
print('age is ' +age)
print('phone is ' +phone)
|
13a03a6d6d627d8f0c36bb4b295a9b89cd8dd36e | lavakiller123/python-1 | /mtable | 333 | 4.125 | 4 | #!/usr/bin/env python3
import colors as c
print(c.clear + c.blue + 'Mmmmm, multiplication tables.')
print('Which number?')
number = input('> ' + c.green)
print('table for ' + number)
for multiplier in range(1,13):
product = int(number) * multiplier
form = '{} x {} = {}'
print(form.format(number,multiplie... |
19240f2deff2c2abe0092025a8d4dde816a0346c | wualbert/r3t | /utils/utils.py | 371 | 3.5625 | 4 | import numpy as np
def wrap_angle(theta):
theta %= 2*np.pi
if theta>=np.pi:
return theta-2*np.pi
else:
return theta
def angle_diff(theta1, theta2):
cw = (theta2-theta1)%(2*np.pi)
cw = wrap_angle(cw)
ccw = (theta1-theta2)%(2*np.pi)
ccw = wrap_angle(ccw)
if abs(cw)>abs(cc... |
0bb9be88da977d144aa1d2ac00252c180c7c2a94 | pauladesh/paul | /paul02/class_instanceVariable.py | 237 | 3.53125 | 4 | class Sample:
def __init__(self):
self.x=11
def modify(self):
self.x+=1
s1=Sample()
s2=Sample()
print('x in s1 =',s1.x)
print('x in s2 =',s2.x)
s1.modify()
print('x in s1 =',s1.x)
print('x in s2 =',s2.x)
|
a6cdac73836ae6276684a269ae22599fdcd8d5d2 | pauladesh/paul | /paul02/static_method1.py | 184 | 3.5 | 4 | class Myclass:
@staticmethod
def mymethod(x,n):
result=x**n
print('{} raised to power {} is {}'.format(x,n,result))
Myclass.mymethod(4,1)
Myclass.mymethod(2,1)
|
55ed2b768b87bdec9ce10dbb0c066960c3980c93 | aliasghar33345/Python-Assignment | /Assignment_4/Assignment_4.py | 4,095 | 4.625 | 5 | #!/usr/bin/env python
# coding: utf-8
# In[1]:
'''Question1:
Use a dictionary to store information about a person you know. Store their first name, last name, age, and the city
in which they live. You should have keys such as first_name, last_name, age, and city. Print each piece of information
stored in your dictio... |
177034604e43405fc616b4ea8c4017f96e8bacea | aliasghar33345/Python-Assignment | /Assignment_5/ASSIGNMENT_5.py | 2,975 | 4.4375 | 4 | #!/usr/bin/env python
# coding: utf-8
# In[1]:
"""
Answer # 1
Write a Python function to calculate the factorial of a number (a non-negative
integer). The function accepts the number as an argument.
"""
def factorial(n):
num = 1
while n > 0:
num *= n
n -= 1
return num
print(factori... |
21a84ea26e71fa0e5bfb8690664fcd69240f454d | theerathat2008/Robotics-MCL | /prac-files/.backups/particleData.py-1574711035200 | 7,695 | 3.609375 | 4 | #!/usr/bin/env python
# Some suitable functions and data structures for drawing a map and particles
import sys
import time
import random
import math
from Particle import Particle
centerToSensor = 5#8.5
sigma = 2
# probability of returning garbage value
k = 0.05
# A Canvas class for drawing a map and particles:
# ... |
2caaf3056ac2a025c7d06db97227635d6e3ca00a | jreese42/heyTV | /logger.py | 877 | 3.75 | 4 | from datetime import datetime
class Logger:
fd = -1
def __init__(self, fd):
"""Initialize a logger instance which will write to fd"""
self.fd = fd
def logDebug(self, text):
"""Print a debug message containing text"""
time = datetime.now().strftime("%H:%M:%S ")
... |
59902bbafdc1a37fbece529b3f03826c93a21611 | thonyaw/FATEC-MECATRONICA-0792011004-ANTHONY | /LTP2-2020-2/Pratica02/programa02.py | 86 | 3.8125 | 4 | numero = float(input('Digite um numero: '))
resultado = numero / 2
print(resultado)
|
7a4fa0a1d94c8d5e6a74d1fee84b76fcbc901d88 | yogirajgutte/Electronic-Arts-Deliverables | /VaxMan/vaxman.py | 18,189 | 3.625 | 4 | import pygame
black = (0, 0, 0)
white = (255, 255, 255)
blue = (0, 0, 255)
green = (0, 255, 0)
red = (255, 0, 0)
purple = (255, 0, 255)
yellow = (255, 255, 0)
Heroicon = pygame.image.load('images/hero.png')
pygame.display.set_icon(Heroicon)
# Add music
pygame.mixer.init()
pygame.mixer.music.load('music.mp3')
pygam... |
147741e39f5d35417c8c1d5e47f07955cdf08f03 | SherazT/DeepNeuralNet | /deep-neural-net.py | 2,474 | 3.65625 | 4 | import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("/tmp/data/", one_hot=True)
no_nodes_hlyr1 = 500
no_nodes_hlyr2 = 500
no_nodes_hlyr3 = 500
n_classes = 10 #outputs
n_inputs = 784
batch_size = 100
#height x width
x = tf.placeholder('float', [None,n_... |
7a5bf78bc03f1008220e365be65e95273686d56f | erik-kvale/HackerRank | /CrackingTheCodingInterview/arrays_left_rotation.py | 2,412 | 4.4375 | 4 | """
------------------
Problem Statement
------------------
A left rotation operation on an array of size n shifts each of the array's elements 1 unit to the left. FOr example,
if 2 left rotations are performed on array [1,2,3,4,5], then the array would become [3,4,5,1,2]. Given an array of n
integers... |
0a1618925280825da66e457194ec4d0a2651bd43 | zhengHugo/applied-DS-coursera | /Assignments_course3/Assignment2/AS2-P1.py | 6,191 | 3.9375 | 4 | import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
np.random.seed(0)
n = 15
x = np.linspace(0, 10, n) + np.random.randn(n)/5
y = np.sin(x)+x/6 + np.random.randn(n)/10
X_train, X_test, y_train, y_test = train_test_split(x, y, random_state=0)
# You can use this function to he... |
756347df8759c2befdb80feabcb255431be085d8 | saiyampy/currencyconverter_rs-into-dollars | /main.py | 898 | 4.28125 | 4 | print("Welcome to rupees into dollar and dollar into rupees converter")
print("press 1 for rupees into dollar:")
print("press 2 for dollar into rupees:")
try:#it will try the code
choice = int(input("Enter your choice:\n"))
except Exception as e:#This will only shown when the above code raises error
print("You... |
f47f46078b511e26258a02fb20b31a7581e6e548 | mohsinhassaan/Project-Euler | /FactorialSum.py | 251 | 3.84375 | 4 | def factorial(n):
if n == 0 or n == 1:
return 1
else:
x = n - 1
while x > 1:
n *= x
x -= 1
return n
n = str(factorial(100))
total = 0
for digit in n:
total += int(digit)
print(total)
|
a16a1dfbba7b71b7538dfe1f45b8b3d9e7ad517b | mohsinhassaan/Project-Euler | /primes.py | 2,441 | 3.546875 | 4 | from math import log
cache = set()
def load_primes(f):
pset = set()
try:
with open(f, "r") as file:
for line in file:
pset.add(int(line.rstrip(",\n")))
except Exception:
with open(f, "w"):
pass
pset = load_primes(f)
return pset
def pr... |
76225c360498f14398a1b7531910656f758f3874 | mohsinhassaan/Project-Euler | /10001stPrime.py | 373 | 4 | 4 | def isPrime(num):
if num == 1 or num == 0:
return False
elif num == 2:
return True
elif num % 2 == 0:
return False
for i in range(3, num // 2, 2):
if num != i and num % i == 0:
return False
return True
count = 0
num = 0
while count < 10001:
num += 1... |
cd496789bdaa3fb08389b6bc0b1f57a8cb110942 | Ambroglio/Advent_of_code-2020 | /12-10/main.py | 2,281 | 3.734375 | 4 | def get_adapters(filename):
adapters = []
with open(filename) as f:
for line in f:
adapters += [(int) (line.replace("\n", ""))]
return adapters
def get_number_of_differences(adapters):
current_adapter = 0
number_of_differences = (0, 0)
max_adapter = max(adapters) + 3
... |
d761240f045f6817eb9d009115f80ff41bb7c8d7 | Ambroglio/Advent_of_code-2020 | /12-08/main.py | 2,048 | 3.5625 | 4 | def get_instructions(file_name):
instructions = []
with open(file_name) as f:
for instruction in f:
instructions += [instruction.replace("\n", "")]
return instructions
def get_accumulator_value(instructions):
executed_instructions = []
accumulator_value = 0
index = 0
... |
2d6ceb13782c1aa23f2f1c9dce160b7cb51cb5f3 | nguya580/python_fall20_anh | /week_02/week02_submission/week02_exercise_scrapbook.py | 2,398 | 4.15625 | 4 | # %% codecell
# Exercise 2
# Print the first 10 natural numbers using a loop
# Expected output:
# 0
# 1
# 2
# 3
# 4
# 5
# 6
# 7
# 8
# 9
# 10
x = 0
while x <= 10:
print(x)
x += 1
# %% codecell
# Exercise 3:
# Execute the loop in exercise 1 and print the message Done! after
# Expected output:
# 0
# 1
# 2
# 3... |
7fa054872e15a47074fd2d1ec5fff49ce547e824 | mungojelly/7by7grid | /py/tkdisplay.py | 588 | 3.6875 | 4 | from Tkinter import *
master = Tk()
total_height = 350
total_width = 350
w = Canvas(master, width=total_width, height=total_height)
w.pack()
colors = []
while len(colors) < 49:
colors.extend(raw_input().split())
cell_height = total_height / 7
cell_width = total_width / 7
current_color = 0
for row in range(7):
... |
9c23f3afc31e514ad1679aded018f86481d627fb | JTRlaze/guessnum | /guess.py | 500 | 3.515625 | 4 | # 產生一個隨機整數1~100
# 讓使用者重複輸入數字去猜
# 猜對的話 印出"終於猜對了!"
# 猜對的話 要告訴他 比答案大/小
import random
r = random.randint(1, 100)
count = 0
while True:
count = count + 1
user = input('請猜數字:')
user = int(user)
print('這是你猜的第', count, '次')
if user == r:
print('終於猜對了!')
break
elif user < r:
pri... |
9cf746000c851cf1c180342028c07d0a1f0cebc6 | MatheusKaussinis/faculdade-impacta | /2 semestre/python/aula05.py | 888 | 3.546875 | 4 | class VeiculoAutomotivo():
# __init__ função está obrigando que a class receba algum valor em seu parâmetro quanto for chamada externamente
def __init__(self, Cilindradas):
self.__Motorizacao = Cilindradas
@property
def Motorizacao(self):
# __ significa que esse atributo só poderá ser ... |
f417b2c790688cd138af77dce2b393af680c146b | stridhar/SeleniumPythonLearning | /Carnival/Conditions1_day4.py | 505 | 4.09375 | 4 | """
#User input
num1 = int(input("Enter a number: "))
num2 = int(input("Enter 2nd number: "))
print(num1+num2)
#or
#print(int(num1)+int(num2))
"""
#Conditions
marks = int(input("Enter your marks: "))
if marks < 35:
print("Fail")
elif marks >= 35 and marks < 45:
print("Pass class")
elif marks >= 45 and marks < 6... |
db31e353c48a532af8aad9e70d00a0875126b250 | stridhar/SeleniumPythonLearning | /Classfive2eight/Day7_Functions.py | 202 | 3.859375 | 4 | #Normal method
def addNumber(a,b):
sumof = a+b
print("Sum of two numbers is:",sumof)
def mulNum(a,c):
mul=a*c
return mul
addNumber(20,30)
addNumber(44,21)
val=mulNum(22,2)
print(val+3) |
943aae5ec8ea5b3d8c11ca5f751d6a0baf7475a0 | stridhar/SeleniumPythonLearning | /Carnival/ImportExample_Day3.py | 326 | 3.625 | 4 | #import math
#print(math.sqrt(4))
#print(math.factorial(4))
#print(math.pi)
# or can be written as #
from math import sqrt,factorial,pi
print(sqrt(4))
print(factorial(4))
print(pi)
#Multiple assignment
x=y=z=50
print(x)
print(y)
print(z)
#Assigning multiple variables in single line
a,b,c=10,20,30
print(a)
print(b)
pri... |
e92389ea51e927c673b0a53543bd7e6893ef8655 | caitig131/Chapter4_Caitlin_Andy | /ex6.py | 245 | 3.6875 | 4 | import turtle
wn=turtle.Screen()
def draw_equitriangle(t,sz):
for i in range (3):
t.forward(150)
t.left(120)
tess=turtle.Turtle()
tess.pensize(3)
size=7
for i in range(1):
draw_equitriangle(tess,size)
wn.mainloop() |
f715d6aab984842d7463779957cb97cdde789b83 | Bugga86/Data_structuresPython | /singly_linked_list.py | 2,335 | 3.984375 | 4 | class Node:
def __init__(self, data):
self.data = data
self.next = None
class linkedList:
def __init__(self):
self.head = None
self.tail = None
def insert(self, data):
newNode = Node(data)
if self.head is None :
self.head = newNode
se... |
b10014a3e6bbe1b94a34570ff4a4263d83a0c941 | grnemchinov/yandex-python | /password.py | 187 | 3.828125 | 4 | n = input()
b = input()
if len(n) < 8:
print('Короткий!')
elif '123' in n:
print('Простой!')
elif b != n:
print('Различаются.')
else:
print('OK') |
862e65ffc81455139ef9eaf8e0f63a4294bff344 | grnemchinov/yandex-python | /seif_24102019.py | 497 | 3.984375 | 4 | name = int(input())
name1 = (name % 10)
name10 = (((name % 100) - name1) / 10)
name100 = (name // 100)
if name1 == name10 == name100:
print('В числе все цифры одинаковые')
elif name1 == name10 > name100 or\
name1 == name10 < name100 or\
name1 == name100 > name10 or\
name1 == name100 < name10 or\
... |
b5b7a8559bb9a35349b552a29ed9242b2b9b00e5 | grnemchinov/yandex-python | /bracket_check.py | 364 | 3.984375 | 4 | def bracket_check(test_string):
result = 0
for a in test_string:
if result == 0 and a == ")":
print("NO")
return
if a == "(":
result += 1
elif ")" in a:
result -= 1
if result < 0:
print("NO")
elif result > 0:
... |
27ab39213bcb2c8fdff29e2f476b4b615fce2a79 | grnemchinov/yandex-python | /draw/nstar.py | 509 | 3.53125 | 4 | import tkinter
import math
master = tkinter.Tk()
canvas = tkinter.Canvas(master, bg='white', height=600, width=600)
canvas.pack()
r = 100
n = int(input())
for k in range(n):
if n % 2 == 0:
k1 = (k + n / 2 - 1) % n
else:
k1 = (k + (n - 1) / 2) % n
p1 = (300 + r * math.cos(2 * 3.14 * k / n), 3... |
665287669d4daee25fc0f8ddc489d93ad5bd7959 | grnemchinov/yandex-python | /teacher_13112019.py | 176 | 3.65625 | 4 | n = int(input())
lst = [set(input() for _ in range(int(input()))) for _ in range(n)]
res = lst[0]
for sch in lst:
res = res.intersection(sch)
print(*sorted(res), sep='\n')
|
8ba17383efa169f17eef15bd1bab7306f0103af0 | grnemchinov/yandex-python | /number_to_word.py | 2,768 | 3.921875 | 4 | dictionary_of_words = {0: 'zero',
1: 'one',
2: 'two',
3: 'three',
4: 'four',
5: 'five',
6: 'six',
7: 'seven',
8: 'eight',
... |
e9963898065b77edfc8bbe7d388651c1638e296d | ngoccc/doanbichngoc-fundamental-c4t2 | /Lesson2/homework/HW_2.py | 259 | 3.75 | 4 | import random
a = []
for i in range(10):
a.append(random.randint(1, 50))
print(a)
even = 0
odd = 0
for i in a:
if i % 2 == 0:
even += 1
else:
odd += 1
print("Number of even numbers: ", even)
print("Number of odd numbers: ", odd)
|
1d360061f2cf487cebf18db92cf4db31bde936f8 | ngoccc/doanbichngoc-fundamental-c4t2 | /Lesson1/Lesson1.py | 444 | 3.65625 | 4 | from turtle import*
shape("turtle")
speed(0)
for i in range(100):
for j in range(4):
forward(100)
left(90)
if (i % 6 == 1): color('red')
if (i % 6 == 2): color('orange')
if (i % 6 == 3): color('yellow')
if (i % 6 == 4): color('green')
if (i % 6 == 5): color('blue')
if (i % 6... |
5eb2680e254e86335b219641fede3d95daf91d1f | ngoccc/doanbichngoc-fundamental-c4t2 | /Lesson2/homework/HW_4.py | 168 | 4.0625 | 4 | import random
n = random.randint(1,9)
guess = int(input("Guess a number: "))
while (n != guess):
guess = int(input("Guess another number: "))
print("Well guessed!") |
dbfb92190a46679048053b8eb322e2a60ea517a1 | Julien-B-py/CSS-Formatter | /main.py | 3,832 | 3.515625 | 4 | def format_css(path) -> None:
"""
Format a CSS file with consistent indentation, spacing and alphabetize on selector names and CSS rules for each
selector.
Not working with media queries and similar structures with multiples levels of "{}".
@param path: Specify the file path you want to format.
... |
75081c31aa68c439a63b8e38f64c62139124e888 | choijy1705/Python | /chap09/01_Exception.py | 6,222 | 3.71875 | 4 |
if __name__ == '__main__':
def my_power(y):
print("숫자를 입력하세요.")
x = input()
return int(x) ** y
print(my_power(2))
'''
# 파이썬의 예외 처리 구문1
try:
# 문제가 없을 경우 실행 할 코드
except:
# 문제가 생겼을 때 실행 할 코드
'''
try:
print(1/0)
except:
print("예외가 발생했습니다.")
print("프로그램 종... |
17a8f20111d7330747d42a29d2283765229aa2bb | 345OOP/Python | /pythonProject5/generatingRandomValues.py | 432 | 4.09375 | 4 | # generating Random Values
import random
# example1
# for i in range(3):
# print(random.random())
# print(random.randint(10,20))
# example2
# members = ['John', 'Mary', 'Lois', 'Clark']
# leader = random.choice(members)
# print(leader)
# example Dice
class Dice:
def roll(self):
first = random.r... |
3ac7b581f715fe7fc2df35234e794eca0d271c9b | NewbDBA/nadocode | /practice.py | 1,944 | 3.75 | 4 | # int = 정수형 ? 숫자형 데이터 // 정수형 데이터는 문자열과 함께 출력 시, 문자열로 바꿔줘야함
# str = 문자열
# boolean = 참 거짓
# 연산자
print(1 == 3) # 앞 뒤가 같음
print(1 != 3) # 앞 뒤가 같지 않음
print(not(1 == 3)) # 위에 거랑 비슷
print((3 > 0) and (3 < 5)) # 2개 다 만족해야함
print((3 > 0) & (3 < 5)) # 위에거랑 같음
print((3 < 0) or (3 > 5)) # 둘 중에 하나만 되도 okay
print((3 < 0) | (3... |
d64a03f26d7dfd8bb4a7899770f29ce560b22381 | Juahn1/Ejercicios-curso-de-python | /ejercicio_1_ecuacion.py | 519 | 4.21875 | 4 | #pasar la ecuacion a una expresion algoritmica (c + 5)(b ^2 -3ac)a^2
# ------------------
# 4a
def ecuacion(a,b,c):
x=((c+5)*((b**2)-3*a*c)*(a**2))/(4*a)
print(f"El resultado es {x}")
try:
a=float(input("In... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.