blob_id
stringlengths
40
40
repo_name
stringlengths
5
127
path
stringlengths
2
523
length_bytes
int64
22
3.06M
score
float64
3.5
5.34
int_score
int64
4
5
text
stringlengths
22
3.06M
94373e71d4d4aaa729f381b299a6394820548067
cukejianya/leetcode
/trees_and_graphs/valid_parentheses.py
643
3.78125
4
class Solution: def isValid(self, s): str_list = list(s) stack = [] while len(str_list): elm = str_list.pop() if elm in "]})": stack.append(elm) elif len(stack) == 0: return False else: match = st...
747d0b1e36338cdccc1eb15e26239fd1813eec76
cukejianya/leetcode
/dynamic_programming/triangle.py
967
3.609375
4
class Solution(object): def minimumTotal(self, triangle): """ :type triangle: List[List[int]] :rtype: int """ for i in range(len(triangle)): if i == len(triangle) - 1: return min(triangle[i]) triangle[i + 1] = self.shortest_path_convers...
f17e4bc522b7902e9bfc91b36ac739d4cf350470
cukejianya/leetcode
/array_and_strings/encode_and_decode_tinyURL.py
855
3.5
4
import string import random class Codec: def __init__(self): self.url_dict = {} def encode(self, longUrl): """Encodes a URL to a shortened URL. :type longUrl: str :rtype: str """ param_array = random.sample(string.ascii_letters + string.digits, 6) ...
6a7af13ffd6a6d130862c4849c011b57c9bb7586
cukejianya/leetcode
/notion/426_convert_binary_search_tree_to_sorted_doubly_linked_list.py
1,040
3.90625
4
""" # Definition for a Node. class Node: def __init__(self, val, left=None, right=None): self.val = val self.left = left self.right = right """ class Solution: def treeToDoublyList(self, root: 'Optional[Node]') -> 'Optional[Node]': found_head = None curr_node = root ...
0f0887cc93752f387f2c7887d749e4ac721de72a
cukejianya/leetcode
/linked_list/reverse_linked_list.py
884
3.78125
4
# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def reverseList(self, head): if head == None: return None return self.reverseListRecur(head)[0] def reverseListRecur(self, head): ...
2f61d9238f4518f476a4ef29fe4431c812ba397f
cukejianya/leetcode
/trees_and_graphs/unique_binary_search_trees_ii.py
709
3.765625
4
# Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: def generateTrees(self, n): if n == 0: return [] DP = {} for start in range(n + 1, 0, -1): ...
8bf756db6183232e427214af5df6d0d67b19b98c
meraj-kashi/Acit4420
/lab-1/task-1.py
286
4.125
4
# This script ask user to enter a name and number of cookies # script will print the name with cookies name=input("Please enter your name: ") number=int(input("Please enetr number of your cookies: ")) print(f'Hi {name}! welcome to my script. Here are your cookies:', number*'cookies ')
b4257afae2f4d101a8a352ad6aa9769be1927642
idimaster/playard
/python/2/sums-list.py
1,292
3.609375
4
from functools import reduce class Node: def __init__(self, data=None, next=None): self.data = data self.next = next def getNum(lst): if lst is None: return 0 return lst.data def sum(lst1, lst2): result = end = None carry = 0 while lst1 or lst2: data ...
b6167e2837b41211811a117618798b145fef7beb
idimaster/playard
/python/other/dep-cycles.py
784
3.796875
4
def cycle(g): for n in g: if dfs(g, n): return True return False def dfs(g, n): if n not in g: return False v = set(n) stack = [n] while stack: node = stack.pop() for next in g[node]: if next == n: return True ...
b7c9f6245c65db0d2f4efd4bb3c38d46688d166d
idimaster/playard
/python/4/bst.py
1,164
3.671875
4
import unittest class Node: def __init__(self, data): self.data = data self.left = None self.right = None def validate(root, min=None, max=None): if root is None: return True if (min is not None and root.data < min) or (max is not None and root.data > max): return...
b0fc40a070ccac366be6bbc2c4a4a9eb179d7e71
idimaster/playard
/python/4/balanced.py
1,293
3.796875
4
class Node: def __init__(self, data): self.data = data self.left = None self.right = None def check(tree): if tree is None: return True if abs(depth(tree.left) - depth(tree.right)) > 1: return False return check(tree.left) and check(tree.right) def depth(tree)...
135605f061e0ef4c8f94b89aad84877f455f7022
iamFIREcracker/project-euler
/python/16.py
101
3.5625
4
"""What is the sum of the digits of the number 2**1000 """ print sum([int(c) for c in str(2**1000)])
9b8092904c38d7347eeff5452a142e3ae8b8e885
iamFIREcracker/project-euler
/python/41.py
449
3.640625
4
"""What is the largest n-digit pandigital prime that exists? """ from itertools import permutations def IsPrime(n): for d in xrange(2, int(n**0.5) + 1): if n%d == 0: return False return True # 1 + 2 ... + 9 = 45 / 3 = 15 # 1 + 2 ... + 8 = 36 / 3 = 12 # 1 + 2 ... + 7 = 28 !!! d = 7 pandig = [p for p in permuta...
2a14afcaa80d1f5669246452f9fafaa27cfab8c9
vikrampruthvi5/pycharm-projects
/TKINTER/01_Plain.py
264
3.5
4
from tkinter import * root = Tk() frame1 = Frame(root) frame1.pack() frame2 = Frame(root) frame2.pack() def foo(): print("Purta") CA1 = Button(frame1, text = "Carrie", command = foo) CA1.pack() CA2 = Label(frame2, text = "Rich") CA2.pack() root.mainloop()
bdf60339654943718159aef76ac693e20c42dc76
vikrampruthvi5/pycharm-projects
/02_conditional-statements/02_for-loop.py
422
4.0625
4
""" For loop """ #count = int(input("Enter value: ")) count = 4 #Ranges from 1 to 4 automatically for i in range(count): print("Pruthvi Vikram - Samyuktha") # Ranges from 2 to 4 for i in range(2, count): print("Samyuktha") # with incrementation for i in range(10, 50, 10): print(i) #Dealing with Strings...
3518d6483fd1ff85f06258bf414f5b5f553feb23
vikrampruthvi5/pycharm-projects
/03_advanced/05_keyword_arguments.py
452
3.5625
4
""" Previously we have seen how to pass values as arguments to the parameters of the function In this example we will see how to send only few values to only one parameters """ from dbm import dumb def dumb_sentence(name='Vikram', action='ate', item='Tuna'): print(name, action, item) dumb_sentence() dumb_se...
9b80a85e7d931de6d78aeddeeccc2c154897a88b
vikrampruthvi5/pycharm-projects
/code_practice/04_json_experimenter_requestsLib.py
1,217
4.125
4
""" Target of this program is to experiment with urllib.request library and understand GET and POST methods Tasks: 1. Create json server locally 2. retrieve json file using url 3. process json data and perform some actions 4. Try POST method """ """ 1. Create json server locally a. From...
5cb010b426cfff62548f9612eabbaad320954a78
vikrampruthvi5/pycharm-projects
/04_DS_ADS/02_dictionaries.py
1,038
4.4375
4
""" Dictionaries : Just like the name says, KEY VALUE pairs exists """ friends = { 'samyuktha' : 'My wife', 'Badulla' : 'I hate him', 'Sampath' : 'Geek I like' } for k, v in friends.items(): # This can be used to iterate through the dictionary and print keys, values print(k ,v) """ Trying...
e485f11804038988fa2480e2bebf3daba56ea906
Kunal0127/Alien_Invasion-By-Kunal
/settings.py
1,430
3.625
4
class Settings(): """A class the store all settings for Alien Invention.""" def __init__(self): """Initialize the game's settings.""" # Screen settings self.screen_width = 1100 self.screen_height = 680 self.bg_color = (255, 255, 255) # Ship settings # self.ship_speed_factor = 1.5 self.ship_limit = 3...
d7613e96f5c2b2fac8a7fd3cb8773368d42d5da6
Hanssel36/Csc113
/Assignment_2/Problem_3.py
231
3.90625
4
def count(String): D = {i:String.count(i) for i in String} A = list(D.items()) Temp = [] D2 = {i:A.count(i) for i in A} for i in A: return Temp arr = [3,3,2,2,2] print(count(arr))
522d19837ca7d97bc1258cd9554f13043473f6d0
DDDYuan/advent-of-code-2019
/AOC-16.py
2,480
3.671875
4
input = '597967370476643225434885050821479669972464655808057915784174627887807404844096256746766609475415714489100070'\ '0282145406894565391148614082316823391528522907537400088802997780034166358604662200362077036173827001424673093'\ '6046471831804308263177331723460787712423587453725840042234550299991238...
eb3dc986c667654edc24bae594d8fb7b472af30a
kevzhang/project_euler
/python/0004.py
221
3.625
4
def isPal(arg): string = str(arg) return string == string[::-1] largest = -1 for x in range(1000): for y in range(1000): product = x * y if isPal(product): largest = max(largest, product) print largest
def29b186bbcf8a575a2191fd0d23edf8f59bac0
kevzhang/project_euler
/python/0024-new.py
258
3.515625
4
import math n = 1000 * 1000 - 1 digits = range(10) output = "" for i in range(9, -1, -1): pseudo_digit = n / math.factorial(i) output += str(digits[pseudo_digit]) n -= pseudo_digit * math.factorial(i) digits.remove(digits[pseudo_digit]) print output
00635dce4ba0db6119d12f0c005da09d8f3f4969
aschiedermeier/Coursera_TensorFlow
/3_2_Convolutions.py
4,548
4.1875
4
###################### # Week 3 # Course 1 - Part 6 - Lesson 3 # Convolutions Sidebar # loads image from scipy.misc, applies a convolution filter and a pool compression # shows 3 pictures in total # https://colab.research.google.com/drive/1XQ8GwKJxuxiSZpvprHFMRaIsDtlekdI0#scrollTo=DZ5OXYiolCUi # https://github.com/lmo...
b0fb74ae01ab19115f6b440675fb50421b9a0c60
jeheonkim/before-2021
/pokerd.py
1,946
3.609375
4
import random redflush = 0 def game(): hand = [] handcolor = [] colors = ["C", "H", "D", "S"] for i in range(5): hand.append(random.randint(7,14)) handcolor.append(random.choice(colors)) avail = ["0", "1", "2", "3", "4"] answer = "" while answer != -1: pri...
83980197772bd12e1e1220d3e4af6f55c3d4d644
Adit-COCO-Garg/rit-cscI141-recitation
/fast_sorts.py
1,806
3.96875
4
# Author @tigranhk # Fast sorting algorithms: Merge and Quick sorts. def mergeSort(lst): if not lst: return lst elif (len(lst) == 1): return lst else: (half1, half2) = split(lst) return merge(mergeSort(half1), mergeSort(half2)) # Split the list into two chunks. def split(ls...
c2063a4d5b46c6e79d82eddc69e1c99b6a72f577
AmandaRM/Projeto-Final-Dsofty
/menu.2.py
530
3.59375
4
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Sat May 19 11:15:39 2018 @author: manucastilla """ import pygame import sys from pygame.locals import * pygame.init() white = (255,255,255) black = (0, 0, 0) tela2 = pygame.display.set_mode((800, 600), 0, 32) pygame.display.set_caption('Star Lego') fund...
2777ef22d02b725780061d605bc28f5e4109d9bb
Nick1306/Python_Web_Console_Program
/Fibo_Frequency.py
2,476
3.546875
4
import collections from collections import Counter import json import math import threading my_list = [] user_timer = () # previous_input = "" time_second = int(input(">> Please input the amount of time in seconds between emitting numbers and their frequency\n")) def Console_Timer(): global user_t...
a96261020cd9849d2771abe79af38e14df71d3ab
calvinccs/notebook
/pidigits.py
420
3.828125
4
def compute_two_digit_freqs(filename): """ Read digits of pi from a file and compute the 2 digit frequencies. """ d = txt_file_to_digits(filename) freqs = two_digit_freqs(d) return freqs def reduce_freqs(freqlist): """ Add up a list of freq counts to get the total counts. """ al...
8951cb9e77aa3101f163db0d1f907aefdea90bce
lsch0lz/grundlagenpython
/Diverses1.py
754
3.828125
4
""" Abschnitt 13 des Python-BootCampns """ #Funktionsparameter benennen """ def multi_print(number = 3, word = "Hallo"): for i in range(0, number): print(word) multi_print() multi_print(5, "Welt") """ #Wie werden Funktionsparameter übergeben a = 5 l = ["Hallo", "Welt"] def f(x): #x.append("111") ...
acefd925fcb1a466b8a0b19b898e50a64c544e6b
joo42110/ProjetISN
/OuvrirPlusieursFenetres.py
615
3.515625
4
from tkinter import * fenetre1 = Tk() fenetre1.title('Fenêtre principale') def Quitter(): fenetre1.destroy() def NouvelleFenetre(): fenetre2=Toplevel() #crée une fenêtre au dessus de la première fenetre2.grab_set() #s'assure "d'attraper" les commandes clavier et souris a=Button(fenetre2,te...
8cd1589468196d6340302fb535f7e2cd1b488615
Arrgentum/practic
/20201001_1/task11.py
556
4.09375
4
def SUB(x,y): if type(x) != type(y): print("Different type") return () elif type(x) == int or type(x) == float or type(x) == set: return x - y else: if type(x) == str: string = str() for i in x: if i not in y: string...
9461233040ff2372417a03f2ccf46ff866764c4e
Arrgentum/practic
/20201015_2/task22.py
683
3.671875
4
import random string1 = "УЁЕУЫАОЭЯИЮ" string2 = "" for i in range(ord("А"), ord("Я")+1): if chr(i) not in string1 and chr(i) not in "ЬЪ": string2 = string2 + chr(i) output_string = "" a = int(input()) i = 0 while i < a: j = random.randint(1,3) if j == 1: output_string = output_string + stri...
45f9a0619c837b68e72467b91e3067033d964009
Arrgentum/practic
/20210301_1/task.py
1,219
3.59375
4
import tkinter as tk class Application(tk.Frame): def __init__(self, master=None): tk.Frame.__init__(self, master) self.grid() self.createWidgets() def createWidgets(self): self.exitButton = tk.Button(self, text='Exit', command=self.exit) self.nextItemButton = tk.Button(self, te...
ef5a828178474b9ef7ffe61302a742950f0ed9ab
Priyanka-Das2/Evaluation
/OddEvenTree.py
410
3.59375
4
class OddEvenTree: def getTree(self, x): if x == ["EOE","OEO","EOE"]: return [0, 1, 2, 1] elif x == ["EO","OE"]: return [0, 1] elif x == ["OO","OE"]: return [-1] elif x == ["EO","EE"]: return [-1] ...
aa322e4df062956a185267130057767ad450dc6e
JRose31/Binary-Lib
/binary.py
937
4.34375
4
''' converting a number into binary: -Divide intial number by 2 -If no remainder results from previous operation, binary = 0, else if remainder exists, round quotient down and binary = 1 -Repeat operation on remaining rounded-down quotient -Operations complete when quotient(rounded down or not) == 0...
a36c8ed98591df3b9c2d756cd22327a0ead9939b
piumallick/Python-Codes
/LeetCode/Problems/0482_licenseKeyFormatting.py
1,298
3.953125
4
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Fri Jan 8 19:48:24 2021 @author: piumallick """ # Leetcode Problem : 482 - License Key Formatting ''' You are given a license key represented as a string S which consists only alphanumeric character and dashes. The string is separated into N+1 groups by...
b9edcf06fd71706e4169ec026dad734f82896578
piumallick/Python-Codes
/LeetCode/Problems/0205_isIsomorphic.py
1,362
4.03125
4
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Fri May 1 23:54:24 2020 @author: piumallick """ # Problem 205: Isomorphic Strings ''' Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the characters in s can be replaced to get t. All occurrences of a character...
5b17c79d9830601e3ca3f21b2d1aa8f334e93f13
piumallick/Python-Codes
/LeetCode/Problems/0104_maxDepthBinaryTree.py
1,405
4.15625
4
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Thu May 14 20:12:03 2020 @author: piumallick """ # Problem 104: Maximum Depth of a Binary Tree ''' Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf n...
c5f5581f816bd354b3ee78d660c58aab13bb3906
piumallick/Python-Codes
/LeetCode/Leetcode 30 day Challenge/April 2020 - 30 Day LeetCode Challenge/02_isHappyNumber.py
1,406
4.125
4
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Sat Apr 25 22:49:19 2020 @author: piumallick """ # Day 2 Challenge """ Write an algorithm to determine if a number n is "happy". A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum...
48a6871dba994b1244835a8fcc2a5edf9b206ca1
piumallick/Python-Codes
/LeetCode/Problems/0977_sortedSquares.py
909
4.1875
4
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Thu May 7 15:01:17 2020 @author: piumallick """ # Problem 977: Squares of a Sorted Array ''' Given an array of integers A sorted in non-decreasing order, return an array of the squares of each number, also in sorted non-decreasing order. Example 1: Inp...
3da3dfcf8bdba08539c1a0ecb23f7a908a8718f6
piumallick/Python-Codes
/LeetCode/Problems/0009_isPalindrome.py
973
4.25
4
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Wed Apr 29 15:46:03 2020 @author: piumallick """ # Problem 9: Palindrome Number """ Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward. Example 1: Input: 121 Output: true Example 2: Input:...
189bde94380bba136d15d1d31f7972f4c64ed8e1
piumallick/Python-Codes
/CrackingTheCodeInterview/Chapter 8 - Recursion and Dynamic Programming/magicIndex.py
1,915
4.0625
4
# Magic Index # A magic index in an array A[1.... n-1] is defined to be an index such that A[i] = i. # Given a sorted array of distinct integers, write a method to find a magic index, if one exists, in array A. # For distinct values in the array # Brute Force method # Linear Scan - Time Complexity: O(n), Space Compl...
a4b659635bbc3dbafabce7f53ea2f2387281daa3
piumallick/Python-Codes
/Misc/largestNumber.py
613
4.5625
5
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Fri Sep 27 10:59:35 2019 @author: piumallick """ # Python Program to find out the largest number in the array # Function to find out the maximum number in the array def largestNumber(arr, n): # Initialize the maximum element max = arr[0] ...
6999d9d645200827a56cbb09970bf084055033a4
njia/scripting
/python/average.py
184
3.828125
4
#!/usr/bin/python import sys def aver(mylist): total, count = 0,0 for number in mylist: total += int(number) count += 1 print float (total/count) aver(sys.argv[1:])
9faf6c10c6dc85f9f295227252122bded0f3033e
qthanglee/algorithm
/anagramcheck.py
660
3.703125
4
#Thang Le #Running time O(n) #will need a logic to check s1 and s2 are characters only. #this only work on assumption of s1 and s2 has no special characters, space.. or numbers def anagramcheck(s1, s2): c1 = [0] * 26 c2 = [0] * 26 for i in range(len(s1)): pos = ord(s1[i]) - ord('a') ...
91ca40bbf64263d7a5b7655b8ae9054a3811634b
toh995/leetcode-practice
/non_leetcode_practice/two_sum.py
866
3.78125
4
# two sum # [1, 2, 3, 5, 6] 8 # [3,5] [6,2] ''' duplicates same pair, different order ''' import math from typing import List def two_sum(arr: List[int], target_sum: int) -> List[List[int]]: if len(arr) < 2: return [] # n log(n) arr.sort() ret = [] for i in range(len(arr)): c...
076e3c6ec63990a1f3235e6b2bcbdcc8fba794d9
toh995/leetcode-practice
/non_leetcode_practice/intertwine.py
608
3.8125
4
# [1, 4, 5, 6 , 9, 7, 2] index = 1 # [1, 6, 4, 9, 6, 7, 2] # [a1, b1, a2, b2, a3, b4 ......] def intertwine(arr: list, index: int) -> list: ''' i = left pointer j = right pointer define a loop, and its stopping conditions - append value(s) to ret - increment pointers ...
853083deec707205a9524b1819fe28aff9b654dc
toh995/leetcode-practice
/easy/0993_cousins_in_binary_tree.py
1,345
3.71875
4
# Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # self.right = right class Solution: def isCousins(self, root: TreeNode, x: int, y: int) -> bool: if (not root) or (root.val in (x, y)): ...
3930d0917b9ad3198f69b631bcb43ed9a4160946
toh995/leetcode-practice
/medium/049_group_anagrams.py
904
3.6875
4
class Solution: # group by sorted string def groupAnagrams1(self, strs: List[str]) -> List[List[str]]: groups = {} for word in strs: sorted_word = tuple(sorted(word)) if sorted_word not in groups: groups[sorted_word] = [word] else: ...
111dc5c85adbebe4192008b5f605389d38677f60
toh995/leetcode-practice
/non_leetcode_practice/two_sum2.py
861
3.609375
4
# two sum # [1, 2, 3, 5, 6] 8 # [3,5] [6,2] import math from typing import List def two_sum(arr: List[int], target_sum: int) -> List[List[int]]: # n log(n) arr.sort() ret = [] while len(arr) >= 2: i = math.floor(len(arr) / 2) complement = target_sum - arr[i] if complement...
9ced5a52c78d8610768ee04848b3248cb7cdbd8c
Wordz278/calculator
/simple_calculator/calculator.py
354
3.671875
4
class Calculator: def __init__(self): pass def add(self, *args): sum = 0 for val in args: num = int(val) sum += num return sum def multiplication(self, *args): product = 1 for val in args: num = int(val) produ...
7680e8ee7df3d1095bae1643e20a0912c053f0f3
Zokkron/Python
/Python3/python13/python13.py
865
3.578125
4
ar = int(input("Eisagete enan arithmo: ")) if len(str(ar)) == 16: _str = str(ar) #χρησιμοποιω την μεταβλητη _str για να μετατρεψω ενα object σε ενα string sum = 0 for n in range (len(_str)): x = ar % 10 ar = ar % 10 if 1 % 2 == 1: x = x * 2 if x > 9: ...
a6e6e481d028b9c8b996f37bb9c798962320b0a9
saxena-sagar/web_crawler
/webScapper.py
1,700
3.84375
4
from urllib.request import urlopen as uReq from bs4 import BeautifulSoup as Bsoup #Beautifulsoup would parse the html text in a page while urllib would grab the page itself. #Web scrapping graphics cards of newegg.com(amazon for hardware electronics) target_url = 'https://www.newegg.com/global/ie/Product/ProductList....
374e7cfd3b00b4aa2d6ab579815b7ee2afccd332
miaokun207/mk
/python 3.9T.py
159
3.96875
4
x={'宋义显': 3,'李东尧':1,'高世玮':2} a=input('请输入要查询的名字:') if a in x : print(x[a]) else: print('您输入的键不存在')
ddbb25e3d971ebcd1c99d19311c721d6ccd7f1ed
ijourdan/habit_rat
/ratlibfunc.py
5,117
3.546875
4
import numpy as np #import math #import pandas as pd # Una coleccion de activation functions def sigmoid(x, derivative=False): if derivative: return x * (1 - x) return 1 / (1 + np.exp(-x)) def tanh(x, derivative=False): if derivative: return 1 - (x ** 2) return np.tanh(x) def relu...
54e3d1683299bb8d38e4481c309250fdfbb545ff
LifeTruther/Training-Portfolio
/Python/preworkquestion2.py
343
3.84375
4
# Question 2: start, end = 0,200 for num in range(start,end): if num % 2 !=0: print(num) # Result from terminal: a list of 100 odd numbers aligned vertically (sometimes they are just stuck together? I could add a space in the output...) #I'm a little intimidated by the immediate complexities that this kind ...
8db22eff5976c05319a06756ad67472ccc6fa845
THABUULAGANATHAN/python
/pro47.py
1,359
3.625
4
import sys, string, math def isPrime(num1) : if num1 <= 1 : return False if num1==2 or num1==3 : return True antt = int(math.sqrt(num1)+1) for i in range(2,antt+1) : if num1%i == 0 : return False return True def factors1(num1) : Laat = [] i = 2 while num1 >1 : ...
42817cfe2500c209dd4384a1211b2b3cbe1ef2c0
THABUULAGANATHAN/python
/4(4).py
99
3.59375
4
thab=input() count=0 for i in range(len(thab)): if(thab[i].isdigit()): count+=1 print(count)
fc901e8fb6faf539c3699059c4f03d484ec790f2
THABUULAGANATHAN/python
/8.py
63
3.5625
4
tk=int(input()) x=0 while(tk>0): x=x+tk tk=tk-1 print(x)
27ddb2586f8eb0660a7613fdd322f0ff506dec12
THABUULAGANATHAN/python
/7.py
92
3.65625
4
tk=int(input()) def hello(x,tk): for i in range(0,tk): print(x) hello("Hello",tk)
fbd832cba3bc58da71e18ae26a31b7ab122cdb9f
THABUULAGANATHAN/python
/1.py
112
3.765625
4
random=int(input()) if(random>0): print("Positive") elif(random<0): print("Negative") else: print("Zero")
c4cb316370c1c58148ff913118fbd2dbc9ec87c9
THABUULAGANATHAN/python
/pro7.py
102
3.59375
4
st=int(input()) mt=0 for vt in range(0,st): if(pow(2,vt)>st): break mt=st-pow(2,vt) print(mt)
6f6d95fbc376453192ab2ebeb4901f63795153de
THABUULAGANATHAN/python
/pro59.py
320
3.78125
4
bht,sbt=map(str,input().split("|")) cct=input() if len(bht)>len(sbt): if len(bht)==len(sbt)+len(cct): print(bht+"|"+sbt+cct) elif len(bht)<len(sbt): if len(sbt)==len(bht)+len(cct): print(bht+cct+"|"+sbt) elif len(bht)==len(sbt) and len(cct)>1 or (len(sbt) or len(bht)): print("impossible")
16b26f355d019feb0af9aa379aa5f9f0a858360d
Ereena/Python-File
/Calculator.py
3,740
3.671875
4
from tkinter import* window = Tk() window.title("Calculator") txt_Input = StringVar() operator = "" def btnClick(num): global operator operator = operator + str(num) txt_Input.set(operator) def btnClear(): global operator operator = "" txt_Input.set("") def btnEquals(): global operato...
78784eb5050732e41908bbb136a0bac6881bc29b
phenom11218/python_concordia_course
/Class 2/escape_characters.py
399
4.25
4
my_text = "this is a quote symbol" my_text2 = 'this is a quote " symbol' #Bad Way my_text3 = "this is a quote \" symbol" my_text4 = "this is a \' \n quote \n symbol" #extra line print(my_text) print(my_text2) print(my_text3) print(my_text4) print("*" * 10) line_length = input("What length is the line?" >) chara...
5e3a49ba630aae781a70b98978efb124562ac7de
phenom11218/python_concordia_course
/Class 2/converter.py
162
3.8125
4
import decimal celcius = -8 Fahrenheit = 9/5*celcius + 32 print(Fahrenheit) print(" The temp in f is {:2.2f}".format(Fahrenheit)) f = 17.6 #Comment is here
b96a9fd528a9ae733359b934b237ca60d1836623
plee-lmco/python-algorithm-and-data-structure
/leetcode/938_Range_Sum_of_BST.py
1,246
3.609375
4
# 938. Range Sum of BST easy # Given the root node of a binary search tree, return the sum of values of all nodes with value between L and R (inclusive). # # The binary search tree is guaranteed to have unique values. # # # # Example 1: # # Input: root = [10,5,15,3,7,null,18], L = 7, R = 15 # Output: 32 # Example 2: # ...
7b3dcb3926a64e0325d011972ed05a346f9fc045
plee-lmco/python-algorithm-and-data-structure
/leetcode/606_Construct_String_from_Binary_Tree.py
2,315
4.0625
4
# 606. Construct String from Binary Tree (Easy) # You need to construct a string consists of parenthesis and integers from a binary tree with the preorder traversing way. # # The null node needs to be represented by empty parenthesis pair "()". And you need to omit all the empty parenthesis pairs that don't affect the ...
ab8d7a0375870036a1357a066cd2ddd26b117cf9
plee-lmco/python-algorithm-and-data-structure
/leetcode/322_coin_change.py
1,768
4.0625
4
# 322. Coin Change Medium # You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return -1. # # Example 1: # # Input: coin...
fb32a1cf3de5588bf6c332a50962e1953ebeecf3
plee-lmco/python-algorithm-and-data-structure
/leetcode/67_Add_Binary.py
578
4.09375
4
# 67. Add Binary Easy # # Given two binary strings, return their sum (also a binary string). # # The input strings are both non-empty and contains only characters 1 or 0. # # Example 1: # # Input: a = "11", b = "1" # Output: "100" # Example 2: # # Input: a = "1010", b = "1011" # Output: "10101" def addBinary(self, a: s...
182eb08a75f6c68d19267e2df99837fb61652cca
plee-lmco/python-algorithm-and-data-structure
/leetcode/557_Reverse_Words_in_a_String_III.py
636
3.96875
4
# 557. Reverse Words in a String III easy # # Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order. # # Example 1: # Input: "Let's take LeetCode contest" # Output: "s'teL ekat edoCteeL tsetnoc" # Note: In the string, each wor...
5ce0153e690d86edc4b835656d290cda02caa2c7
plee-lmco/python-algorithm-and-data-structure
/leetcode/23_Merge_k_Sorted_Lists.py
1,584
4.15625
4
# 23. Merge k Sorted Lists hard Hard # # Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. # # Example: # # Input: # [ # 1->4->5, # 1->3->4, # 2->6 # ] # Output: 1->1->2->3->4->4->5->6 def __init__(self): self.counter = itertools.count() def mergeKLists(self,...
3ae51c10a011c6c212d24052fed3d42dabcccc1f
plee-lmco/python-algorithm-and-data-structure
/leetcode/141_Linked_List_Cycle.py
1,735
3.96875
4
# 141. Linked List Cycle Easy # Given a linked list, determine if it has a cycle in it. # # To represent a cycle in the given linked list, we use an integer pos which represents the position (0-indexed) in the linked list where tail connects to. If pos is -1, then there is no cycle in the linked list. # # # # Example 1...
e973bd49b0115d1c1b663bfd0839a777de4c952b
adarshashok7/area
/Postive.py
287
3.78125
4
lst = [] n = int(input("NO OF ELEMENTS: ")) for i in range(n): element = int(input("ELEMENTS: ")) lst.append(element) print("\nINPUT LIST 1 = ", lst) for a in lst: if a<0: lst.remove(a) print("\nLIST 2 = ", lst)
9665365b272224097beae8e9ea17ba6acac47c36
Bayesd/student-group-divider
/main.py
1,616
3.96875
4
MAXIMUM_GROUP_SIZE = 6 MINIMUM_GROUP_SIZE = 2 DEFAULT_GROUP_SIZE = 4 class Students: def __init__(self, name, position): self.name = name self.position = position + 1 self.has_met = [] def get_students(): return open("student_list.txt", "r").readlines() def number_of_students(): ...
cec13d4024f52f100c8075e5f1b43408790377bb
aquatiger/misc.-exercises
/random word game.py
1,175
4.5625
5
# does not do what I want it to do; not sure why # user chooses random word from a tuple # computer prints out all words in jumbled form # user is told how many letters are in the chosen word # user gets only 5 guesses import random # creates the tuple to choose from WORDS = ("python", "jumble", "easy", "difficult"...
7a729648eb97e2026a8656cada8cdbee6bf483ac
MarvinTeichmann/CS231n
/Week1/tutorial.py
3,549
4.09375
4
def quicksort(arr): if len(arr) <= 1: return arr pivot = arr[len(arr) / 2] left = [x for x in arr if x < pivot] middle = [x for x in arr if x == pivot] right = [x for x in arr if x > pivot] return quicksort(left) + middle + quicksort(right) print quicksort([3,6,8,10,1,2,1]) ## Basic types x = 3 print...
30be4f414ed675c15f39ccf62e33924c7eb9db3b
Deepanshudangi/MLH-INIT-2022
/Day 2/Sort list.py
348
4.46875
4
# Python Program to Sort List in Ascending Order NumList = [] Number = int(input("Please enter the Total Number of List Elements: ")) for i in range(1, Number + 1): value = int(input("Please enter the Value of %d Element : " %i)) NumList.append(value) NumList.sort() print("Element After Sorting List in Asce...
34028b34420e05f24493049df0c8b5b0391eb9b9
sammaurya/python_training
/Assignment6/Ques4.py
879
4.4375
4
''' We have a function named calculate_sum(list) which is calculating the sum of the list. Someone wants to modify the behaviour in a way such that: 1. It should calculate only sum of even numbers from the given list. 2. Obtained sum should always be odd. If the sum is even, make it odd by adding +1 and if the sum...
456c9e5ef3cb81c4d50c75a1e55a5e33fe303b3a
sammaurya/python_training
/Assignment2/Ques1.py
611
3.859375
4
# Ques1: # Given a list of tuples, the task is to remove all tuples having duplicate first values from the given list of tuples. # Input: [('Tuple1', 121), ('Tuple2', 125), ('Tuple1', 135), ('Tuple4', 478)] # Output: [('Tuple1', 121), ('Tuple2', 125), ('Tuple4', 478)] input = [('Tuple1', 121), ('Tuple2', 125), ('...
2b5069c18e127d08dbaf55b1e0c7da11f1f87440
sammaurya/python_training
/classes.py
1,090
4.1875
4
# class A: # def __init__(self): # self.name = "sam" # self._num = 9 #protected # self.__age = 22 #private # a = A() # print(a.name, a._num) # a.__age = 23 # print(a._A__age) # print(dir(a)) # a = 8 # b=10 # print(a.__add__(2)) # for i in range(5): # print(i) # print(range(5))...
84ccc40b48bc00939f8cd81a3cf91d2c809214ea
saran-1998/RL-based-Pattern-Formation
/Pattern_Formation_Reinforcement_Learning/drones.py
5,895
3.5
4
import turtle as t import math import time class Drones(): def __init__(self, n, starting_points, final_points): self.done = False self.reward = 0 self.win = t.Screen() self.win.title('Drones') self.win.bgcolor('black') self.win.setup(width=600, height=600) ...
2eda9966254c6d9938788c7f54ef17481e7fa4b2
sahilsehgal81/python3
/timeconv.py
475
4.0625
4
#!/usr/bin/python seconds = eval(input("Enter the time in seconds: ")) minutes = seconds // 60 hours = minutes // 60 microseconds = seconds * 60 print('You have entered ', seconds,'Seconds. Which are equals to ', minutes, ' Minutes. And equals to ', hours, ' hours. And equal to ', microseconds, ' ms.\n Thanks for ...
485609b657e6125c36139286c6eb9c64b5c1c234
sahilsehgal81/python3
/squarerootcomparison.py
466
3.703125
4
#!/usr/bin/python from math import fabs, sqrt def equals(a, b, tolerance): return a == b or fabs(a - b) < tolerance; def square_root(val): root = 1.0 diff = root*root - val while diff > 0.0000001 or diff < -0.00000001: root = (root + val/root) / 2 diff = root*root - val return root def main(): d = 1.0 wh...
38ffc0b99a22ecfc5e06396f343bd40bb3c95ba1
sahilsehgal81/python3
/primefunc.py
385
4.0625
4
#!/uar/bin/python from math import sqrt def is_prime(n): root = sqrt(n) value = True trial_factor = 2 while value and trial_factor <= root: value = (n % trial_factor != 0) trial_factor += 1 return value def main(): max_value = int(input("Enter an Integer value: ")) for value in range(2, max_value +1):...
9b8934a4947dcbf6ac6bd3bfc41d0245137c1b50
sahilsehgal81/python3
/gcd.py
421
3.921875
4
#!/usr/bin/python def gcd(m, n): if n == 0: return m else: return gcd(n, m % n) def iterative_gcd(num1, num2): min = num1 if num1 < num2 else num2 largestFactor = 1 for i in range(1, min +1): if num1 % i == 0 and num2 % i == 0: largestFactor = i return largestFactor def main(): for num1 in range(1, 1...
e7a9cfe2e5bbcc3456d69863f2b5a93fc9c20e97
sahilsehgal81/python3
/floatequals.py
201
3.53125
4
#!/usr/bin/python from math import fabs def equal(a, b, tolerance): return a == b or fabs(a - b) < tolerance; def main(): i = 0.0 while not equal(i, 1.0, 0.01): print("i= ",i) i += 0.1 main()
5d0e99f7e604778d72531f5a4b5655b0efc958d9
sahilsehgal81/python3
/listcopy.py
388
3.890625
4
#!/usr/bin/python def list_copy(lst): result = [] for list in lst: result += [list] return result def main(): a = [10, 20, 30, 40] b = list_copy(a) print("a = ", a, " b = ", b) print("Is", a, "equals to ", b, "?", sep="", end=" ") print(a == b) print("Is", a, "an alias of", b, "?", sep="", end=" ") pri...
428a9f84cc1cbc8e100c82dd046b83fbd9a3f746
sahilsehgal81/python3
/gcdwithmain.py
361
3.84375
4
#!/usr/bin/python def gcd(n, m): min_num = n if n < m else m largestFactor = 1 for i in range(1, min_num + 1): if n % i == 0 and m % i == 0: largestFactor = i return largestFactor def get_int(): return int(input("Enter the value of an Integer: ")) def main(): n = get_int() m = get_int() print("gcd for",...
44f4b11f6819b285c3698ab59571f03591ad72b8
sahilsehgal81/python3
/computesquareroot.py
308
4.125
4
#!/usr/bin/python value = eval(input('Enter the number to find square root: ')) root = 1.0; diff = root*root - value while diff > 0.00000001 or diff < -0.00000001: root = (root + value/root) / 2 print(root, 'squared is', root*root) diff = root*root - value print('Square root of', value, "=", root)
72baf11c8a5b2ffc4480c989b053e217f803bdc7
SoorajKothari/Kaggle-Data-sets-Model-Basic-Training-in-Python-
/Q2.py
663
3.6875
4
#Q2 import pandas as pd import numpy as np my_dict = {"country":["United States","Australia","Japan","India","Russia","Morocco","Egypt"], "dr":[True,False,False,False,True,True,True], "cpc":[809,731,588,18,200,70,45]} cars = pd.DataFrame(my_dict) print(cars) cars.index = ["US","AUS","JAP","IN"...
697787f5d7857566a8640e4523cca4b806d734fb
LeeKaiYing/Bomb-Shelter
/HW2/Shaun The Sheep.py
1,210
3.6875
4
sheep_sizes = [5, 7, 300, 90, 24, 50, 75] print ("Hello my name is Le and these is my sheep sizes") print (sheep_sizes) a = max(sheep_sizes) print('Now my biggest sheep has size' ,a, 'lets sheer it!') list_2 = [x + 50 for x in sheep_sizes] print ("After 1 month, now here is my flock", list_2) b = max(list_2)...
8ad4b80f5ed6895afcad35639129daf4013d1f85
lidiyam/algorithms
/array_and_strings/license_key_formatting.py
372
3.671875
4
def licenseKeyFormatting(S, K): """ :type S: str :type K: int :rtype: str """ s = S.replace("-", "").upper() n = len(s) start = n % K a, l = '', 0 for i in range(start, n, K): if i == 0: continue a += s[l:i] + "-" l = i return a + s[l:] if __name__ =...
9f32d23e97691c8709041640105610ef864fb120
lidiyam/algorithms
/dp/matrix_chain_multiplication.py
1,020
3.796875
4
""" Given a chain <A1,A2,..,An> of n matrices, where for i = 1,2,...n, matrix Ai has dimension p(i-1) x p(i), fully parenthesize the product A1 * A2 * ... An in a way that minimizes the # of scalar multiplications. """ import sys # Bottom up approach # Input p: list of matrices dimensions [p0, p1, ..., pn] def matrix...
266a5684f39e56df05796affa88853981dd3c92f
lidiyam/algorithms
/math/modular_exp.py
348
3.796875
4
def modular_pow(n, k, m): if m == 1: return 0 result = 1 n = n % m while k > 0: if (k % 2 == 1): result = (result * n) % m k = k // 2 n = (n * n) % m return result if __name__ == '__main__': print modular_pow(3,8,5) print modular_pow(3,6,5) ...
841f7e28d6d87571a964fcd9baa8c06e261602b5
lidiyam/algorithms
/array_and_strings/kmp.py
999
3.515625
4
""" KMP algorithm - compares the pattern to the text left-to-right - shifts pattern if mismatch occurs (depends on failure arr) KMP Failure Array F[j] = len of largest prefix of P[0..j] that is also a suffix of P[1..j] built in O(m) time """ def failureArray(P): m = len(P) F = [0]*m i = 1 j = 0 wh...
ed9029259122365714058cc58bceaea8a663937d
lidiyam/algorithms
/array_and_strings/trapping_rain_water.py
762
3.765625
4
""" Given n non-negative integers representing an elevation map, compute how much water it is able to trap. """ class Solution(object): def trap(self, height): """ :type height: List[int] :rtype: int """ start, end = 0, len(height)-1 total = 0 level = 0 while start <= end: level = max(level, min(he...
dbc6ae065c5940e74d75fe3602b17c5f7ad00d22
lidiyam/algorithms
/dp/0-1_knapsack.py
940
3.78125
4
""" Given a list of items with values and weights, as well as a max weight, find the maximum value you can generate from items where the sum of the weights is less than the max. """ class Solution(object): # bottom up approach def knapsack(self, vals, weights, maxWeight): T = [] for x in rang...
0c207abae3b80e5d507fad6cf2f16c855c553a18
Gilb03/tk-
/app.py
267
3.5
4
import tkinter as tk root = tk.Tk() frame = tk.Frame(root) frame.pack() button = tk.Button(frame, text="CLICK ME", fg="red", command=lambda: print("Hello")) button.pack(side=tk.LEFT) root.mainloop()