blob_id
string
repo_name
string
path
string
length_bytes
int64
score
float64
int_score
int64
text
string
476dddd1cd9422027cc144df149f423f79cf4bea
AK-1121/code_extraction
/python/python_23686.py
112
3.78125
4
# Python program that tells you the slope of a line def slope(x1, y1, x2, y2): return (y1 - y2) / (x1 - x2)
1076b7c138e0bbfde4a6a75d0fb2d02bd8098b76
AK-1121/code_extraction
/python/python_22401.py
134
3.8125
4
# Python dict print One per line with Key in each line for k, v in dict.iteritems(): for item in v: print item, k
b794117908cc5a5fdf872d09dc410759a700196e
AK-1121/code_extraction
/python/python_1889.py
193
3.828125
4
# How many items in a dictionary share the same value in Python import itertools x = {"a": 600, "b": 75, "c": 75, "d": 90} [(k, len(list(v))) for k, v in itertools.groupby(sorted(x.values()))]
c88b7692f63fb2293176c795e0c836546cc61cbf
AK-1121/code_extraction
/python/python_6729.py
135
3.953125
4
# How to find and split a string by repeated characters? import itertools [''.join(value) for key, value in itertools.groupby(my_str)]
580f93b43a77ab44a2a1db92c44afec1a4f891d8
AK-1121/code_extraction
/python/python_8360.py
100
3.578125
4
# How can I re-order the values of a dictionary in python? dict = { 'a': [ "hello", "hey", "hi" ] }
1344c1b2ae8a0eb3790ece2b56558107650bd8e4
AK-1121/code_extraction
/python/python_16516.py
139
3.765625
4
# Get values in Python dictionary from list of keys >>> d = {'a':1, 'b':2 , 'c': 3} >>> [d[k] for k in ['a','b']] [1, 2]
c752436b645b522e14f3754c6b62b4e28cdbb84a
AK-1121/code_extraction
/python/python_7488.py
118
3.59375
4
# If clause in regular Python for-loop for elem in (item for item in my_list if not (item=='')): #Do something...
b9a4669298be2e54294d5e561730c87213901b3c
AK-1121/code_extraction
/python/python_15473.py
184
4.09375
4
# How do I capture words wrapped in parentheses with a regex in Python? >>> print re.search("(\w+) vs (\w+) \(\s?(\w+)",my_string).groups() (u'Hibbert', u'Bosh', u'Chalmers')
72198b39cfa9f4a50e01925e36c0e31705076cc1
AK-1121/code_extraction
/python/python_11332.py
166
3.640625
4
# Print a string as hex bytes? >>> s = "Hello world !!" >>> ":".join("{:02x}".format(ord(c)) for c in s) '48:65:6c:6c:6f:20:77:6f:72:6c:64:20:21:21
548499cad3c1943ee6dfd5b217896a3d8980ebf1
AK-1121/code_extraction
/python/python_810.py
178
3.53125
4
# How do we remove all non-numeric characters from a string in Python? >>> import re >>> re.sub("[^0-9]", "", "sdkjh987978asd098as0980a98sd") '987978098098098'
a44ff01fbfad42e5ad4c3832fbf12275761f2752
AK-1121/code_extraction
/python/python_6280.py
118
3.828125
4
# Python: How to remove all duplicate items from a list for i in mylist: if i not in newlist: newlist.append(i)
a40fe3f3c05f44275f813b77dd30d30b52d9ce51
AK-1121/code_extraction
/python/python_11911.py
141
3.546875
4
# Quickly applying string operations in a pandas DataFrame splits = x['name'].split() df['first'] = splits.str[0] df['last'] = splits.str[1]
147f61e09873b1a06d43ac89e62dd911f2255358
AK-1121/code_extraction
/python/python_12526.py
115
3.515625
4
# Python list iteration and deletion cpt1 = sum(1 for x in liste if x != 2) cpt2 = sum(1 for x in liste if x == 2)
7ad81539ef1f7c2a96eda52d75946e02bf6ef0ff
AK-1121/code_extraction
/python/python_19506.py
261
3.6875
4
# How to turn multiple lists into a list of sublists where each sublist is made up of the same index items across all lists? >>> [list(x) for x in zip(lsta, lstb, lstc)] [['a', 'a', 'a'], ['b', 'b', 'b'], ['c', 'c', 'c'], ['d', 'd', 'd']] >>>
4c995afb28c05267673a570e2b7db969e4753119
AK-1121/code_extraction
/python/python_27527.py
179
3.59375
4
# Python - How to ensure all lengths of elements in a nested list are the same? def evenlengthchecker(nestedlist): a = [len(i) for i in nestedlist] return len(set(a)) ==1
6b63ae2af00ca8f44e2db16e6de01edfc9d93204
AK-1121/code_extraction
/python/python_22105.py
138
3.5625
4
# How to compare two timezones in python? from datetime import datetime today = datetime.today() b.utcoffset(today) == c.utcoffset(today)
35a0b2ff6bac17344addaf96bc1be0ca15a08161
AK-1121/code_extraction
/python/python_9812.py
134
3.6875
4
# Find length of 2D array Python numrows = len(input) # 3 rows in your example numcols = len(input[0]) # 2 columns in your example
5b5d6d3d45147d2580854262e451114d5057b774
AK-1121/code_extraction
/python/python_4038.py
152
3.578125
4
# Python - extracting a list of sub strings >>> import re >>> re.findall("{{(.*?)}}", "this {{is}} a sample {{text}}") ['is', 'text']
0d66f830a27373ca25b591cfaee034782d8a68f9
AK-1121/code_extraction
/python/python_16345.py
197
3.78125
4
# Count of a given item in a particular position across sublists in a list a = [[(1, 2), (2, 1)], [(1, 2), (1, 2)], [(2, 3), (2, 2)]] item = (1,2) count = [sublist[0] for sublist in a].count(item)
78b2c424f665f1102bf6c03717acfad82bcae5cc
AK-1121/code_extraction
/python/python_23709.py
127
3.53125
4
# Possible to extract a List from a Dictionary of Lists in Python? >>> [v[2] for v in dictionary1.values()] [3, 8, 4]
2e6df9b4398fb70a7ffcee5946a46dbd3760e2b8
AK-1121/code_extraction
/python/python_10090.py
130
3.515625
4
# Python creating a list with itertools.product? new_list = [item for item in itertools.product(*start_list) if sum(item) == 200]
41aa661021a9cdc427acf900aa3b113dd9148175
AK-1121/code_extraction
/python/python_27233.py
153
3.859375
4
# how to search and print dictionary with python? for fruit, colors in fruitdict.items(): print('{} have {} color.'.format(fruit, ' '.join(colors)))
1c7dba4975d98b94c818f19407521072526835e7
AK-1121/code_extraction
/python/python_13725.py
119
3.578125
4
# python - find index postion in list based of partial string indices = [i for i, s in enumerate(mylist) if 'aa' in s]
9541deba98d2ac5e7aa48210bc3c00ec3cccc14e
AK-1121/code_extraction
/python/python_20777.py
132
3.796875
4
# How to check if number is integer number, with good precision? def is_square(x): s = int(sqrt(x) + 0.5) return s * s == x
c3f56f9899499a6d739b35609510ad2fd1ac2f3f
AK-1121/code_extraction
/python/python_28511.py
159
4.125
4
# How do I check if a string with a user given input is equal to a certain letter/ word in Python while (userin!="c" or low == high): userin = raw_input()
055d3ddebde5f37f0be08e61e5d92cf8ad404085
AK-1121/code_extraction
/python/python_4982.py
214
3.90625
4
# How to turn a string of letters into 3 letter words in Python 2.7.1 >>> a = "aaabbbcccdddeeefffggg" >>> [a[i:i+3] for i in range(0, len(a), 3)] ['aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff', 'ggg']
a2138590d660f64db3986ecceddd12f2aa468ada
AK-1121/code_extraction
/python/python_17964.py
158
3.65625
4
# read a file into python and remove values import re with open('filename', 'r') as f: list1 = [re.split('[(#]+', line.strip())[0].split() for line in f]
579335e8b69662eb02c7b03955176d3a7092c406
AK-1121/code_extraction
/python/python_25897.py
142
3.65625
4
# Can't show the key along with the value (dict) in Python chris = {'name': 'chris', 'avg': (test1['chris']+test2['chris']+test3['chris'])/3}
3baafdb2f02476dabfe5a2fef5497e7339fde92e
AK-1121/code_extraction
/python/python_7542.py
244
3.640625
4
# Using append() on transient anonymous lists inside of a list comprehension in Python >>> mylist = [['A;B', 'C'], ['D;E', 'F']] >>> [first.split(';') + [second] for first, second in mylist] [['A', 'B', 'C'], ['D', 'E', 'F']]
c0d5a3602f4eb79c2b43e626893c6247407b876b
AK-1121/code_extraction
/python/python_5763.py
106
4.46875
4
# Determining whether an value is a whole number in Python if x % 3 == 0: print 'x is divisible by 3'
378ca5bd0cba18a6fc426830d426a9da86b9d8a8
AK-1121/code_extraction
/python/python_10377.py
173
3.546875
4
# Python comma delimiting a text file with open('infile.txt') as infile, open('outfile.txt', 'w') as outfile: outfile.write(', '.join(infile.read().split('\n')) + '\n')
b681468218d7c401794d2b647c44143f29def2c7
AK-1121/code_extraction
/python/python_20575.py
159
3.828125
4
# nested lists and for loops program in python gives me a crazy result for index in range(len(listOne)): listThree.append((listOne[index],listTwo[index]))
3ac026d604620fde8e9c43fd5d3a3927c0fbbe0b
AK-1121/code_extraction
/python/python_1413.py
65
3.5
4
# Convert string / character to integer in python chr(ord(ch)+2)
16841661256962d06c4ed690fad2a2bf36bd7e48
AK-1121/code_extraction
/python/python_11305.py
239
3.71875
4
# Generate arrays that contain every combination of elements from an array >>> from itertools import combinations >>> list(combinations('ABCD', 2)) [('A', 'B'), ('A', 'C'), ('A', 'D'), ('B', 'C'), ('B', 'D'), ('C', 'D')]
9b60a2532870799654cd3ac4270073524b0c935a
AK-1121/code_extraction
/python/python_6006.py
156
3.59375
4
# In list of dicts, match dict based on one key/value? fields = ('name', 'school') match_found = any(all(x[f]==example[f] for f in fields) for x in myList)
d53208c80311d53fb840a9251357b2aca4858ac9
AK-1121/code_extraction
/python/python_21646.py
172
3.90625
4
# how to check whether a string A is contained into a longer string B for any combination of upper/lower character def checkString(a, b): return a.lower() in b.lower()
591d16c6d2897f2eb88c4e674bb724cf6397fe83
AK-1121/code_extraction
/python/python_24770.py
139
3.53125
4
# Adding spaces in elements of list(PY) def equalize_lengths(l): length = len(max(l, key=len)) return [e.ljust(length) for e in l]
fb54a3820745b1b0655c507133caa2b4e93c9646
AK-1121/code_extraction
/python/python_23285.py
99
3.515625
4
# Python 3.4.1 Print new line print('\n', even_count, ' even numbers total to ', even_sum, sep='')
444b0159c5387f71d09d0b5171787b4e6d36a73c
AK-1121/code_extraction
/python/python_18020.py
150
3.78125
4
# Python, rename a list with one of its values all_my_lists = {} #USE A DICT!!! all_my_list[listx[2]] = listx #listx[2] gives the 3rd value in listx
39cfa8c5c6723a90dcaa140d5e69d51bed4b11e6
AK-1121/code_extraction
/python/python_24967.py
121
3.546875
4
# I would like explanations on python list management optimisation, and overall, optimisation a += 3 if condition else 1
8fecdcad39c372035ef51216a7a4b9bb7ee7d63a
AK-1121/code_extraction
/python/python_7787.py
105
3.53125
4
# Convert string to ASCII value python >>> s = 'hi' >>> [ord(c) for c in s] [104, 105]
8a0a6d2153984e1230e000ae3a61a97cc740aa71
AK-1121/code_extraction
/python/python_26679.py
207
3.78125
4
# Using regular expression to catch phrases in Python >>> regex = re.compile("Who created (.*?)\?", re.I) >>> regex.search("Who created Lord of the Rings?").groups()[0] 'Lord of the Rings'
d7d60b7a4305b0dcfa39a431103cb337dfefd191
AK-1121/code_extraction
/python/python_21764.py
149
3.515625
4
# how to write contents into a file in python where one part holds a variable and other just a display statement? f.write("value of a is: %d" % (a))
625d22b61e26d16297b45175effab19759669a86
AK-1121/code_extraction
/python/python_1460.py
122
3.609375
4
# nesting python list comprehensions to construct a list of lists f = open(r"temp.txt") [[c for c in line] for line in f]
41b6edffae54c2430c509a9232f5edf73a69336e
AK-1121/code_extraction
/python/python_18977.py
141
3.78125
4
# How to convert a list into a column in python? >>> y = [1,2,3,4,5,6] >>> [[i] for i in y] [[1], [2], [3], [4], [5], [6]]
acb16498a7ffd9d530ddbe1aeeb9a569ca3470a2
AK-1121/code_extraction
/python/python_21197.py
117
3.71875
4
# String replacement using modulo in Python for raw_input? age = raw_input("Hello %s, please enter your age" % name)
74cb69dab523fb7efd2b3c073308e61d5cf40635
AK-1121/code_extraction
/python/python_16917.py
136
3.59375
4
# How to delete items on the left of value1 and on the right of value2 in a list of ints in Python? l[l.index(start): l.index(end) + 1]
494f1fb26d7ed8cfe6a446f3a1bdaf825c79c7b7
AK-1121/code_extraction
/python/python_25229.py
128
3.5
4
# I want to move a item to first index in list. How to simplify code? sorted([0,1,2,3,4,5], key=lambda x: x == 2, reverse=True)
1d5bc806fb435f6b85c866c1aa93088f1ba3edb4
AK-1121/code_extraction
/python/python_3461.py
87
3.6875
4
# Using Python's re to swap case >>> s = "AbcD" >>> s.lower() 'abcd'
046892680ee0760bff80a0385b0b8c25cf07a457
AK-1121/code_extraction
/python/python_23262.py
104
3.65625
4
# Printing every item on a new line in Python print '\n'.join([str(factorial(x)) for x in range(0, 6)])
fafd811980cf1546673b90d336d5e5a01632b099
lensvol/advcode2016
/python/day1.py
2,073
3.640625
4
# -*- coding: utf-8 -*- ''' Day 1 of the Advent of Code challenge, parts A and B ''' import sys NORTH = 'N' SOUTH = 'S' EAST = 'E' WEST = 'W' LEFT = 'L' RIGHT = 'R' MOVEMENTS = { (NORTH, LEFT): ((-1, 0), WEST), (NORTH, RIGHT): ((1, 0), EAST), (SOUTH, LEFT): ((1, 0), EAST), (SOUTH, RIGHT): ((-1, 0...
bee23ecce30ac852f84b350b7fe484a9af1ec369
vikramcse/Hackerrank
/Algorithms/Strings/Pangrams/panagram.py
256
3.671875
4
str = raw_input().strip().lower() alpha_positions = [0] * 26 flag = True for c in str: if c != " ": pos = ord(c) % 26 alpha_positions[pos] = 1 for i in alpha_positions: if not i: flag = False if flag: print "pangram" else: print "not pangram"
63f0ad6223769c03f80c5fd6e8f6d6ccef18c849
WilderSiguantay/PythonBasico
/Clase 2/Clase2.py
2,138
4.09375
4
#Esto es un comentario de una linea ''' Este es un comentario de varias lineas ''' #La funcion print se usa a menudo para imprimir variables print('Hola') #Python no tiene ningun comando para declarar variables mivariable = 0 x = 5.10 y = 'Hola Mundo' x1= 5 y2 = 'David' #Las variables incluso pueden cambiarse de ...
7dd862e71dc7a9e1aa21bdee868db02e5fd371ae
Pikselas/word-detector
/main.py
2,136
3.703125
4
# word detector and replacer import os import tkinter as ui def Search(WORD,REPLACE,extension): print("WORD ->> "+str(WORD)+"\nREPLACER ->> "+str(REPLACE)+"\nEXTENSION ->>"+str(extension)) print("**********SUMMARY*************") contents = os.listdir("Input//") for items in contents: if...
ec82f694bad7211232ba662b9fc09748123d9661
jdaekwang/Algebra-
/chapter3.py
653
3.890625
4
from chapter2 import * from inspect import signature def is_commutative(f_binary,domain): i = 0 while i < len(domain): j = 0 while j < len(domain): try1=f_binary(domain[i],domain[j]) try2= f_binary(domain[j],domain[i]) if try1 != try2: return ...
cb34a9664bd64f3c81e23a5fb1fbda0b8d52b510
fischly/FoIP-2020
/homeworks/question4.py
1,053
3.5
4
# -*- coding: utf-8 -*- """ Homeworks - Question 4 """ # read the image img= cv2.imread('./imagesHW/hw3_road_sign_school_blurry.JPG',0) # copy the image to perform the transformations im = img.copy() # select the kernel that is used for dilation-erosion W = cv2.getStructuringElement(cv2.MORPH_CROSS,(5,5)) ...
c7805ecaa052f94617ccf5043eb2ae78e20ee1ba
yngz/discrete-optimisation
/knapsack/algos.py
2,024
4.09375
4
def greedy_trivial(capacity, items): """A trivial greedy algorithm for filling the knapsack. It takes items in-order until the knapsack is full. """ value = 0 weight = 0 taken = [0]*len(items) is_optimal = 0 for item in items: if weight + item.weight <= capacity: tak...
6ba104c9ea7ebcaff8d1a310adaf414fc4e90ed3
ngk3/AdventOfCode2017
/Star17.py
2,155
3.890625
4
# Function used to get the total_score from a string of groupings (garbage is erased) def get_total_score(group_string): # total_count tracks the total score, count tracks the current grouping score total_score = 0 count = 0 # Go through each character in the string for gs in group_string: ...
221e4d56f9112b5c58c93a9fe0b9b4833a9aecce
ngk3/AdventOfCode2017
/Star12.py
2,027
4.09375
4
# Function used to turn the banks into a String representation def banks_to_string(banks): returning = "" for i in banks: returning += str(i) + " " return returning.strip() # Function used to redistribute the banks based on the given position and the highest value found def redistribute(banks, position, highest...
3f33c301eea0937ba8c14e60b30a9133c2770a7f
ngk3/AdventOfCode2017
/Star42.py
7,141
3.5625
4
# class to represent a Grid of lights class Grid: # Initializes a grid based on a gridstring (look at input file to see gridstring format) def __init__(self, gridString = ".#./..#/###"): gridString_splitted = gridString.split("/") self.map = [] for gs in gridString_splitted: ...
fa5a41a746942e83af4c38071143488552fd6f84
i-vs/tree-practice
/binary_search_tree/tree.py
4,323
3.9375
4
# some descriptive blocks and None's are for readability class TreeNode: def __init__(self, key, val=None): if val == None: val = key self.key = key self.value = val self.left = None self.right = None class Tree: def __init__(self): self.root = Non...
b3a16e0f14a5221be418de9d5162ad97cff9fba0
JoelDarnes88/primer_programa
/2.0.-Come_helado.py
532
4.1875
4
apetece_helado = input("¿Te apetece helado? (Si/No): ") tiene_dinero = input("Tienes dinero (Si/No): ") esta_el_señor_de_los_helados = input("esta el señor de los helados (Si/No) ") esta_tu_tia = input("¿Estás con tu tía? (Si/No)") Te_apetece_helado = apetece_helado == "Si" puedes_permitirtelo = tiene_dinero == "Si" o...
ebe6c06d7f547761f10f2c10df4f4cd033009859
amysolman/CMEECourseWork
/Week3/Code/get_TreeHeight.py
867
3.5625
4
#!/usr/bin/env python3 # Date: Dec 2019 """Takes input file of tree distances and degress, calculates height and outputs results file with input file name.""" __appname__ = 'get_TreeHeight.py' __author__ = 'Amy Solman (amy.solman19@imperial.ac.uk)' __version__ = '0.0.1' import sys import pandas as pd import os impor...
ce7f395b4defb63095c402233d486ebb73724b4a
amysolman/CMEECourseWork
/Week2/Code/using_name.py
1,008
3.78125
4
#!/usr/bin/env python3 # Date: Oct 2019 # Filename: using_name.py """In shell either run using_name.py (for ipython) or python3 using_name.py. Script will generate several different functions using different conditionals.""" # Before python runs the code in a file it sets a few special variables, # __name__ is one ...
0429ec1c03247b819b282ebb33731b095d39a2da
amysolman/CMEECourseWork
/Week2/Code/basic_io3.py
1,023
3.6875
4
##!/usr/bin/env python3 ############################# # STORING OBJECTS ############################# __appname__ = 'basic_io3.py' __version__ = '0.0.1' """ In shell either run basic_io3.py (for ipython) or python3 basic_io3.py. Script will create a dictionary and save it to testp.p then load the data again and save...
6dd8b8449ec2670b9dd39bbd8decf2ba67171437
niksimon/python-stuff
/tutorial/lists.py
148
3.796875
4
friends = ["Joe", "Jack", "Jessica", "Oscar", "Poe", "Tim", "Mike", "Jim"] print(friends) print(friends[-1]) #print(friends[1:]) print(friends[1:3])
96eade2293d5ca717943b148bb12d21dd1110912
niksimon/python-stuff
/google-foobar-challenges/google_lvl4_challenge1.py
3,747
3.6875
4
def testPair(a, b): sum = a + b _min = min(a, b) # If sum of two numbers is divisible by min number and (sum / 2) / min is a power of two then two guards will reach same number of bananas and we don't want that pair so return False power = sum // 2 // _min if(sum % 2 == 0 and sum % _min == 0 a...
3e2ba4c06bbdecb708dbcbdfbbbd3311c4ebce80
niksimon/python-stuff
/tutorial/classes.py
273
3.734375
4
class Student: def __init__(self, name, age, is_on_probation): self.name = name self.age = age self.is_on_probation = is_on_probation def print(self): print(self.name + " " + str(self.age)) s = Student("simon", 26, False) s.print()
48551a04d331f77d4fe2fa110c1f647ba6d07e28
Haseenamenda/pal
/sta.py
273
3.71875
4
def midchenge(): k=input() n=len(k) l=list(k) k='' if n%2!=0: for i in range(n//2): k+=l[i] k+='*' j=n//2+1 else: for i in range(n//2-1): k+=l[i] k+='**' j=n//2+1 for i in range(j,n): k+=l[i] print(k) try: midchenge() except: print('invalid')
7d81a11bce57d7cc0f2105630ef611762a195882
mariumi96/lab2_repo
/arr_algs.py
474
3.84375
4
def find_min(arr): if arr: min = arr[0] for el in arr: if el < min: min = el return min else: print('Массив пуст!') def avr(arr): if arr: a = 0 for el in arr: a = a + el n = len(arr) return a / n el...
6cada4baa7361aa9b5180f270bf09423e33b11e6
Kole19/pyVezbe
/Prost broj.py
284
3.59375
4
def prost_br(broj): dalije=0 for x in range(2,broj): if broj%x is 0: dalije+=1 if dalije >= 1: print("Broj nije prost.") else: print("Broj je prost.") a = input("Unesi broj: ") broj = int(a) prost_br(broj)
ec0f71c1275537052ef07e924758a5bcbe4786b3
hsherkat/AOC2020
/day19.py
1,826
3.5625
4
""" Advent of Code 2020: Day 19 https://adventofcode.com/2020/day/19 """ import re from itertools import product from typing import Dict def get_matches(rule: str, rules_dict: Dict[str, str]): pattern = r'"([a-z]+)"' if (match := re.search(pattern, rule)) : # base case, single letter c = match.group...
092393145094c02a579ac74628820ba053f1bad2
hsherkat/AOC2020
/day01.py
1,423
4.0625
4
""" Advent of Code 2020: Day 1 https://adventofcode.com/2020/day/1 """ from typing import List, Tuple from collections import Counter from itertools import product def find_pair_sums_to_N(nums: List[int], N: int) -> Tuple[int, int]: if (N % 2 == 0) and nums.count(N // 2) > 1: return (N // 2, N // 2) ...
1bc276f7d38d0414a2897aeba366acd3c2613eb1
hsherkat/AOC2020
/day08.py
1,575
3.6875
4
""" Advent of Code 2020: Day 8 https://adventofcode.com/2020/day/8 """ with open("input_8.txt") as f: x_input = [row.strip() for row in f] def parse_instruction(instr): op, num = instr.split(" ") val = int(num) return op, val def execute_instruction(instructions, row_num): op, val = parse_inst...
af242c1ae86592272b3c02dcfdfc67575e0d3b6e
pijel/assorted-algos
/add_linked_lists.py
1,088
3.78125
4
# Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = x # self.next = None import math class Solution(object): def addTwoNumbers(self, l1, l2): """ :type l1: ListNode :type l2: ListNode :rtype: ListNode """ ...
2c2cbc8c02307881723e1a88b7b2245855164a23
pijel/assorted-algos
/remove_k_from_end.py
853
3.8125
4
# Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = x # self.next = None class Solution(object): def removeNthFromEnd(self, head, n): """ :type head: ListNode :type n: int :rtype: ListNode """ retur...
0a19fd4970421e0ff69b418993eb302fa5f6a747
pijel/assorted-algos
/trapping_rainwater.py
1,210
3.90625
4
class Solution: def trap(self, height): """ :type height: List[int] :rtype: int """ if height == []: return 0 return how_much_water(height) def how_much_water(height): elevation = 1 rain_water = 0 while elevation <= max(height): ...
f9a5831098d43874164173820338090a76384130
pijel/assorted-algos
/merge_k_linked_lists.py
1,502
3.859375
4
# Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = x # self.next = None class Solution(object): def mergeKLists(self, lists): """ :type lists: List[ListNode] :rtype: ListNode """ return mergeklists(lists) ...
28e9553712f9c3c8311600858170029d619dc219
renanlage/naive-bayes
/remove_old_players.py
1,558
3.65625
4
#function that removes the players from older seasons that do not have all the data available... def remove_players(regular_season_path, player_career): # opening files regular_file = open(regular_season_path, 'r') player_career_file = open(player_career, 'r') # read files to memory as lists playe...
bfd4c97134b9bcae8eb5d553b94988aed968cc49
JMU-ROBOTICS-VIVA/jmu_ros2_util
/jmu_ros2_util/map_utils.py
5,643
3.5
4
"""Map class that can generate and read OccupancyGrid messages. Grid cell entries are occupancy probababilities represented as integers in the range 0-100. Value of -1 indicates unknown. Author: Nathan Sprague Version: 10/29/2020 """ import numpy as np from nav_msgs.msg import OccupancyGrid from geometry_msgs.msg i...
4b873329812e2af982c4c137b52cd5da86dccdeb
update-ankur/Hackerrank_30daysOFcode
/30 days of code( python)/Day 24.py
682
3.703125
4
def removeDuplicates(self,head): #Write your code here if head is None: return current_node = head counter = 0 list_data = {} index = 0 while (current_node is not None): if (list_data.get(current_node.data) is None): lis...
ccae5bbd74ff61ad83eb4a315f75bfa33c51a14b
update-ankur/Hackerrank_30daysOFcode
/30 days of code( python)/day10.py
558
3.609375
4
#!/bin/python3 import math import os import random import re import sys def tobinary(n): s = "" while n>0 : s = str(n%2) + s n = n//2 return s def func(n): s = tobinary(n) i = 0 mx = -1 while i < len(s): count = 0 while i < len(s) and s...
729267ed2e25066aa0aeceedd01d8168c523609a
SGiuri/word-count
/word_count.py
261
3.59375
4
import re from collections import Counter def count_words(sentence): clear_sentence = re.sub(f"[^a-zA-Z0-9\']", " ", sentence) words = [word.strip("'").lower() for word in clear_sentence.split()] all_words = Counter(words) return all_words
23ecdab8a0a6c0e0f61d41b8588e580e74169412
CdavisL-coder/automateTheBoringStuff
/spam.py
208
3.84375
4
#this is an example of a while loop #value of spam is 0 spam = 0 #while spam is less than 0, print quote while spam < 10: print("T'is but a scratch!") #adds 1 to spam every time spam = spam + 1
6f2581f4fafe6f3511327d5365f045ba579a46b1
CdavisL-coder/automateTheBoringStuff
/plusOne.py
372
4.21875
4
#adds one to a number #if number % 3 or 4 = 0, double number #this function takes in a parameter def plus_one(num): num = num + 1 #if parameter is divided by 2 and equal zero, the number is doubled if num % 2 == 0: num2 = (num + 1) * 2 print(num2) #else print the number else: ...
73c96ebcfebcf11ad7fde701f001d8bdbd921b00
poljkee2010/python_basics
/week_2/2.3 max_of_three.py
215
4.1875
4
a, b, c = (int(input()) for _ in range(3)) if a < b > c: print(b) elif a < c > b: print(c) elif b < a > c: print(a) elif a > b or a > c: print(a) elif b > a or b > c: print(b) else: print(c)
753cf5fe690b21cf11c657121b12b4570a70f691
poljkee2010/python_basics
/week_3/3.16 delete_the_fragment.py
109
3.578125
4
string = input() first, last = string.find("h"), string.rfind("h") print(string[:first] + string[last + 1:])
46c7273f57bbd0d029797bef3868cbb6af63425e
poljkee2010/python_basics
/week_3/3.8 gorner_scheme.py
131
3.671875
4
n = int(input()) x = float(input()) total = 0 for _ in range(n + 1): total += float(input()) * x ** n n -= 1 print(total)
1292602718d97a0c5441e0085f947b82f45bcf57
poljkee2010/python_basics
/week_4/4.4 is_point_in_square.py
163
3.78125
4
a, b = (float(input()) for _ in range(2)) def IsPointInSquare(x, y): return -1 <= x <= 1 and -1 <= y <= 1 print("YES " if IsPointInSquare(a, b) else "NO")
a246d744c2e821983838421a0dc8df5a7ba265be
poljkee2010/python_basics
/week_3/3.23 replace_but_first_and_last.py
159
3.703125
4
string = input() first = string.find("h") last = string.rfind("h") print(string[:first + 1] + string[first + 1: last].replace("h", "H") + string[last:])
8686b7e0d8eeca93d4516689950f455193e60d06
poljkee2010/python_basics
/week_7/7.6 count_words.py
169
3.734375
4
words_set = set() with open("input.txt", "r") as f: for line in f: for word in line.strip().split(): words_set.add(word) print(len(words_set))
33938b7c55842e4bb85ce3651015dfed0704b0f1
poljkee2010/python_basics
/week_5/5.17 larger_than_previous.py
132
3.5625
4
lst = [int(num) for num in input().split()] for i in range(1, len(lst)): if lst[i] > lst[i - 1]: print(lst[i], end=" ")
56cb66f9227a10f6158b84f32fa5fda4675f70b0
maryclarecc/python-challenge
/PyPoll/main.py
2,915
3.515625
4
import os import csv import numpy as np from numpy.core.fromnumeric import mean, sort csvpath = os.path.join('Resources', 'election_data.csv') with open(csvpath, "r") as csvfile: # CSV reader specifies delimiter and variable that holds contents csvreader = csv.reader(csvfile, delimiter=',') # Read t...
bade4df0766758c49699a8d4465cecc828179f8c
Roy19/codeforces
/python/4a.py
203
4
4
def divide(n): if (n % 2 != 0) or n == 2: return 'NO' else: return 'YES' if __name__ == '__main__': n = int(input().strip()) result = divide(n) print(result)
b427deccf1a96603788f6220f2d3970643586a4d
amedesc/mantsoft-fidu-2019
/jrh8.py
625
3.625
4
def darmensaje(mensaje): print("Hola Mundo" + mensaje) darmensaje(" es mi primera vez en python ") #crear una funcion PatternCount que cuenta cuántas veces aparece #un patrón Pattern en una cadena de caracteres Text. print("Buenas por favor ingrese un texto donde se repita un patrón y luego ingresa el patrón") ...
0b4c4f72772ccc99908b02721287a1b85c1157f0
amedesc/mantsoft-fidu-2019
/fertico21.py
730
3.546875
4
# Esta función concatena 2 cádenas de texto. # Recibe como parametro un mensaje y retorna "Hola mundo" + mensaje enviado. def darmensaje(mensaje): print ("Hola mundo!", mensaje) darmensaje("Fernando") # Esta Función determina la frecuencia con la que un patrón aparece en una cadena de texto. # Recibe como parám...
958a950e7f1bed0601a54bd349d9bd873a12223f
Parashar7/Introduction_to_Python
/Sqaureroot.py
183
4.375
4
import math print("This is the program to find the square root of a number:") num=int(input("Enter a number:")) sqrt=math.sqrt(num) print("Square root of "+ str(num)+ " is \n" , sqrt)
c1c638da823de134b079145344476ee9aa8d9b42
Parashar7/Introduction_to_Python
/Automated_Billing.py
1,329
3.9375
4
print("\t\t\t\t\tThis is a program to automate a Billing System\n\n\n") pre_mon=int(input("Enter the Previous Month Home Units: ")) cur_mon=int(input("Enter the Current Home Month Units: ")) ac1=int(input("Enter the Previous A.C Month Units: ")) ac2=int(input("Enter the Current A.C Month Units: ")) print("Home Uni...
17e5dcdb6b83c5023ea428db1e93cc494d6fe405
Parashar7/Introduction_to_Python
/Celsius_to_farenheight.py
217
4.25
4
print("This isa program to convert temprature in celcius to farenheight") temp_cel=float(input("Enter the temprature in Celsius:")) temp_faren= (temp_cel*1.8) +32 print("Temprature in Farenheight is:", temp_faren)
3e052311d7fa93da4d8d7a1c4d4a3c2c8c39e666
shirtsgroup/InterMol
/intermol/atom.py
4,182
3.703125
4
class Atom(object): """ """ def __init__(self, index, name=None, residue_index=-1, residue_name=None): """Create an Atom object Args: index (int): index of atom in the molecule name (str): name of the atom (eg., N, CH) residue_index (int): index of residue i...