blob_id
string
repo_name
string
path
string
length_bytes
int64
score
float64
int_score
int64
text
string
is_english
bool
99176b408587d5094b85640a4798c4ff5abc8145
codebreaker-00/Learn-python
/if_statements_in_python.py
717
4.1875
4
car = 'subaru' # no check for if else part in the double quotes part print("Is car == 'subaru'? I predict True.") print(car == 'subaru') #prints boolian for this condition print("\nIs car == 'audi'? I predict False.") print(car == 'audi') #prints boolian for given condition # while checking inequality or equality in ...
true
403bed7eaad732ac495237aace0875f712dc3962
GreenBlitz/GBVision
/gbvision/tools/list_tools.py
702
4.25
4
from typing import Callable, Iterable, T def split_list(f: Callable[[T], int], lst: Iterable[T], amount=2): """ splits the list into several list according to the function f :param lst: the list to split :param f: a function which maps from an argument to the index of the list it should go to ...
true
7a12f613dad780192523902bfe8bfd93af7ab57e
Sayanta-B/interview_practice
/Users/Sayanta/PycharmProjects/Interview/Practice/prime.py
252
4.125
4
def isprime(n): for i in range(2,n-1): if n%2 ==0: return False else: return True if __name__=="__main__": if isprime(8): print("the no is prime") else: print("The no is not prime")
true
a21f03479bfc2d45e3a1f5d87e45b18009981f64
jerryq27/Cheatsheets
/Tutorials/Languages/Python/10AppsCourse/App08_FileSearch/playground.py
957
4.25
4
def factorial(n): if n == 1: return n else: return n * factorial(n - 1) def fibonacci(limit): nums = [] current = 0 next = 1 while current < limit: current, next = next, current + next nums.append(current) return nums def fibonacci_co(limit): current =...
true
09e676e13f216fa0f9fe735a0bd7578a98eda133
andrewjsiu/anomaly_detection
/insight_testsuite/temp/src/network.py
1,957
4.125
4
# -*- coding: utf-8 -*- """ Author: Andrew Siu (andrewjsiu@gmail.com) ------------------------------------------------- Detecting Large Purchases within a Social Network ------------------------------------------------- Build functions to get a set of all friends within a specified nu...
true
82b522ec4abc601d1eff1dd0705dc467980b5f95
techtronics/BIA660-2013S
/course_docs/20130122/Assignment1_Jie_Ren.py
702
4.15625
4
"""Jie Ren""" password = str(raw_input('Enter your password(you can inter any character):\n')) key = str(raw_input('Enter your key(you can inter any charater):\n')) def encoding(password, key): a = password + key b = "" for i in a[::-1]: b += chr(ord(i)+6) return b print 'After encrypti...
true
ce94ea7b869b4746c4f9c318c0c0eb26fb157688
wooihaw/intropyjune2021
/04_switch_case.py
499
4.3125
4
# Make a function switch_case that, given a string, # returns the string with uppercase letters in lowercase # and vice-versa. Include punction and other non-cased # characters unchanged. # # >>>> switch_case("Arg!") # aRG! # >>>> switch_case("PyThoN") # pYtHOn def switch_case(string): # Add code here t...
true
18409fdc191e742aba1aee5057feee502886eabc
simonszuharev/designing-python
/day 26 (NATO game)/main.py
331
4.15625
4
# {new_key:new_value for (index, row) in df.iterrows()} import pandas data = pandas.read_csv("nato_phonetic_alphabet.csv") letter_words = {row.letter: row.code for (index, row) in data.iterrows()} print(letter_words) name = input("Enter a word: ").upper() nato_list = [letter_words[letter] for letter in name] print(...
true
7ca7199d821066acd5fd518d79bd849ff8d7f4aa
rsha0812/Data-Structure-Python-
/Data Structure/Qn based on Circular linked List/Code 1(Insertion of new node).py
1,811
4.25
4
''' #Code : Insertion of new node in Circular Linked List: 1) Insert at end(Condition) : >> for Empty list >> if list has data 2) Insert at beginning(condition): >> for Empty list >> if list has data ''' # Code class Node: def __init__(self,data=None,...
true
a3635e1e016644ca2087fa71d413b3f8d328270a
kehillah-coding-2020/PPIC03-ForresterAlex
/set_c.py
1,823
4.34375
4
#!/usr/bin/env python3 # # pp. 99, 103 # from encrypt_functions import * """ 3.17 With paper and pencil, use the transposition algorithm to encrypt the sentence "the quick brown fox jumps over the lazy dog." Check your answer by calling the `scramble2Decrypt` function. """ #TEQIKBONFXJMSOE H AYDGH UC RW O U P V R TELZ...
true
6defbbaa8076bf456b0e7e515e9b59f22da6803f
khalidflynn/PythonForInformaticsCourse
/Chapter 08 - Lists/8.4Lists.py
779
4.65625
5
#8.4 Open the file romeo.txt and read it line by line. For each line, split the line into a list of words using #the split() method. The program should build a list of words. For each word on each line check to see if the word #is already in the list and if not append it to the list. When the program completes, sort ...
true
715682a2ac435705000c20541ca23f15adb1bd17
khalidflynn/PythonForInformaticsCourse
/Chapter 05 - Iteration/5.2Loops and Iteration.py
945
4.21875
4
#5.2 Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. #Once 'done' is entered, print out the largest and smallest of the numbers. #If the user enters anything other than a valid number catch it with a try/except and put out an #appropriate message and ignore the number...
true
1fba4a9478c6637d0e019111d9502a69c6a79925
KushagrJ/PY-00
/35 (#)/35.py
1,658
4.40625
4
# -*- coding: utf-8 -*- # Python 3.8.6 def main(): print("Enter a list of integers: ", end = "") listOfNumbers = [int(i) for i in input().split()] listOfNumbers.sort() targetValue = int(input("Enter the integer to be searched: ")) print() binary_search(listOfNumbers, targetValue) def binar...
true
91f8d3bc4ba581bae571fbe7b94b6e90850dd515
KushagrJ/PY-00
/41 (#)/41.py
601
4.4375
4
# -*- coding: utf-8 -*- # Python 3.8.6 def fibonacciSequence(n): if n < 3: return n-1 else: return (fibonacciSequence(n-1)+fibonacciSequence(n-2)) n = 0 while n < 1: n = int(input("Enter the number of terms of the Fibonacci sequence: ")) for x in range(n): if x == n-1: print...
true
dd300a0df32e0bc40d4237c5a7666518d6fb51e0
sglim/inno-study
/leetcode/ino/prob_345/prob_345_reverse_vowels_of_a_string(1).py
1,766
4.15625
4
# fail. time limit ''' Write a function that takes a string as input and reverse only the vowels of a string. Example 1: Given s = "hello", return "holle". Example 2: Given s = "leetcode", return "leotcede". Note: The vowels does not include the letter "y". ''' class Solution(object): def get_left_vowels(self...
true
f6b402123f9ef16470846f1551381a9cbcc749f9
sglim/inno-study
/leetcode/ino/prob_345/prob_345_reverse_vowels_of_a_string(2).py
1,097
4.125
4
# fail. time limit ''' Write a function that takes a string as input and reverse only the vowels of a string. Example 1: Given s = "hello", return "holle". Example 2: Given s = "leetcode", return "leotcede". Note: The vowels does not include the letter "y". ''' class Solution(object): def reverseVowels(self, ...
true
69a4417b797ad4c1266f0ce99f7a003760464c16
olesbober/edabit-challenges
/hex_to_binary.py
433
4.28125
4
## Hex to Binary # Create a function that will take a HEX number and returns the binary equivalent (as a string). ## Examples # to_binary(0xFF) ➞ "11111111" # to_binary(0xAA) ➞ "10101010" # to_binary(0xFA) ➞ "11111010" ## Notes # The number will be always an 8-bit number. def to_binary(num): s = "" ...
true
fc7f42230fe6395ad18f41be6146636e1ee42682
santibarbagallo/introcs
/Conditions.py
551
4.25
4
#conditional keywoards #If (argument) #action #Else #action #If (argument1) #action #Elif (argument1 #action #Elif (argument1 #action #Else #action #Operators for conditions #Less than : < #Greater than : > #Equal : == #Not equal : != #Less than or equal to : <= #Greater than or equal to ...
true
25da8b9d9980634fcee84f1d7b247b0dd4130794
Alex-Villa/Lab5
/Heap.py
1,791
4.1875
4
class Heap: def __init__(self): self.heap_array = [] def insert(self, k): self.heap_array.append(k) self.percolate_up(len(self.heap_array) - 1) def percolate_up(self, node): while node > 0: parent_node = (node - 1) // 2 # Used to find parent of current node ...
true
eae46786607d873e2e0b2ed4817e5401020e71d8
NathenJohns/python-testing
/if_statements.py
394
4.28125
4
is_male = False is_tall = True if is_male and is_tall: print("You are a tall male") elif is_male and not(is_tall): print("You are a short male") elif not (is_male) and is_tall: print("You are a not a male but are tall") else: print("You are either not male not tall or both") # Can use 'and' both ...
true
0a819e4cea507f24c7bf31e76fb42590298d9e49
anoop600/Python-Basics-Learn
/6. Sequences/sorting_list.py
257
4.3125
4
even = [2,4,6,8] odd = [1,3,5,7,9] even.extend(odd) print(even) #Sort method will not create new list insted it uses the same list even.sort() print(even) print(id(even)) even.sort(reverse=True) print(even) print(id(even)) # even.reverse() # print(even)
true
2363b4f5baebbbdee016e6e8382f88aaf34724a8
kunal01996/python-essentials-for-ds
/basics/python-tutorial-eu/for-loop.py
516
4.25
4
# Learning for-loop in python edibles = ["ham", "spam", "eggs", "nuts"] for food in edibles: if food == "spam": print("No more spam") break else: print("I am glad i finished my food without any spam this time!") print('I am stuffed!') # Pythagorean triplets from math import sqrt n = int(inpu...
true
ae8f79e2eaec78c353fdbcc0db01319d1cad08bd
DiginessForever/LaunchCodeLC101Challenges
/dataStructures/binaryTree.py
2,776
4.21875
4
class TreeNode: value = 0 left = None right = None def __init__(self, value): self.value = value def insert(self, value): if self.value > value: if type(self.left) != TreeNode: self.left = TreeNode(value) else: self.left.insert(value) elif self.value <= value: if type(self.right) != TreeNo...
true
2e7a03b7f37981f06e191a32494c22c84db538f6
shubhamkochar/Python_Codes
/List/OccurrenceOfElementsInList.py
449
4.1875
4
# Python code to count the occurrence of elements in a list def count(list,x): count = 0 for ele in list: if ele == x: count +=1 return count lst = [1,2,2,3,3,3,4,4,4,4,5,5,5,5,5,6,6,6,6,6,6,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,10,10] num = int(input...
true
691bd6f49e0a6945133a5fdd895653b738ab4342
shubhamkochar/Python_Codes
/String Programs/RemoveAllDuplicatesFromString.py
306
4.34375
4
# Python code to remove all duplicates from a string def removeDuplicate(string): print("Original String: ",string) r ="" for i in string: if (i in r): pass else: r = r+i print("String after removing duplicates: ",r) removeDuplicate("repetition")
true
1b829786aa0ef345a657de1a9b8cb908508d12d4
shubhamkochar/Python_Codes
/String Programs/LeastFrequentCharacter.py
403
4.375
4
# Python code to find the least frequent character from a string def least_frequent(s): print("Entered string: ",s) frequency ={} for i in s: if i in frequency: frequency[i] +=1 else: frequency[i]= 1 result = min(frequency) print("Minimum of all character in...
true
d6984f4b61a3be852e6036cfa7ced4c58a9d4934
shubhamkochar/Python_Codes
/String Programs/ReverseWordsOfString.py
262
4.34375
4
# Python code to reverse words of a given string def reverse_str(s): print("Original string: ",s) splited = s.split(" ") reverse = " ".join(reversed(splited)) print("Reversed string: ",reverse) reverse_str("Python is a programming language")
true
f5aeed02e4cccfaeca1be0604d26e12f64012716
shubhamkochar/Python_Codes
/SwapingTwoNumbers.py
386
4.28125
4
# Python code to swap two numbers with using third variable num1 = int(input("Enter first number: ")) num2 = int(input("Enter second number: ")) # printing values before swaping print("First number is",num1,"and second number is",num2) # swaping values num1,num2 = num2,num1 # printing values after swaping print("A...
true
7196ff620b5c679c245d20b0ca7dda3dbf8de955
shubhamkochar/Python_Codes
/String Programs/PermutationOfGivenStringUsingInbuiltFunction.py
288
4.25
4
# Python code for permutation of given strings using from itertools import permutations def allpermutation(string): permuList = permutations(string) for x in list(permuList): print("".join(x)) if __name__ == "__main__": string = "ABC" allpermutation(string)
true
19fc3ffcfc611f22f1b86cb9732d9ecb9dd59ef7
chandra122/UdemyChallenges
/challenge1.py
597
4.40625
4
# To Calculate the sum of three given numbers # if the variables are equal then sum should be double # def sum_of_three(a,b,c): # result = 0 # if a == b == c: # result = 2*(a+b+c) # else: # result = a+b+c # print("The result of three is : ",result) # # sum_of_three(10,10,20) # To Swap ...
true
08faa996874eb65aea1b736ecf1b39e777a01fec
Cattleman/python_for_everybody_coursera
/8.5.py
1,118
4.34375
4
""" @author: Hensel 8/30/16 Assignment 8.5 : strip out email address 8.5 Open the file mbox-short.txt and read it line by line. When you find a line that starts with 'From ' like the following line: From stephen.marquard@uct.ac.za Sat Jan 5 09:14:16 2008 You will parse the From line using split() and print out the ...
true
eb874b7dcb915b3046b49fc2a58e2622d6895ed1
jcshott/interview_prep
/interview_cake/product_of_others.py
780
4.375
4
def product_of_others(array): """takes a list of integers and returns a list of the products of the integers at the other indices example: >>> nums = [1, 7, 3, 4] >>> out = product_of_others(nums) >>> out [84, 12, 28, 21] calculate by [7*3*4, 1*3*4, 1*7*4, 1*7*3] """ ## in this version we are doubling work. ...
true
23cccb6fb3f89e2e7b4dcb4175424010cf40df30
jcshott/interview_prep
/split/split.py
1,763
4.1875
4
def split(astring, splitter): """Split astring by splitter and return list of splits. This should work like that built-in Python .split() method [*]. YOU MAY NOT USE the .split() method in your solution! YOU MAY NOT USE regular expressions in your solution! >>> split("i love balloonicorn", " ") ...
true
176701d502bc4b1613a175a3f226dacf18e57971
jcshott/interview_prep
/cracking_code_interview/ch8_recursion/magic_index.py
1,030
4.15625
4
def magic_index_recursion(array): """ magic index is defined as given array A, if A[i] == i, return True input: sorted array of distinct integers ouput: true/false if there is a magic index """ def _magic_idx(array, idx): """since we are only given a sorted array in problem, define recursive function to cal...
true
a497f95869053036b6f1c51c3fadee811589387e
YunheWang0813/RPI-Repository
/CSCI 1100/HW/HW4/hw4_files/hw4_files/hw4_part1(test).py
920
4.4375
4
"""Author: <your name and email> Purpose: This program reads a word from user input and prints whether the word is at least 8 characters long, starts with a vowel, alternates vowels and consonants and the consonants are in increasing alphabetical order. """ ######### Put all your function definitions h...
true
cfb134980edd489874fbeaf95e3cddb3f6116119
faranik/training
/stacks_queues/p33.py
2,022
4.15625
4
""" Stack of Plates: Imagine a (literal) stack of plates. If the stack gets too high, it might topple. Therefore, in real life, we would likely start a new stack when the previous stack exceeds some threshold. Implement a data structure SetOfStacks that mimics this. SetOfStacks should be composed of several stacks and ...
true
e2ad39301fc388f749ff774fd3a40ab9abc3cb5a
predtech1988/Courses
/data_structures/exercise/09/stack_implem_Llist.py
1,690
4.21875
4
# Stack Implementation (Linked Lists) class Node: def __init__(self, data=None, next=None) -> None: self.data = data self.next = next class Stack: def __init__(self) -> None: self.top = None self.bottom = self.top self.length = 0 def peek(self): if self.l...
true
ad4aa726b451a7b06702cb414f4f6825bf2f48dc
antgouri/IPP2MCA
/April25th, 2020 class/palindrome.py
223
4.5
4
val = input("Enter the string value\n") print(end="\n") rev = val[::-1] #Simplest method to reverse a string value. if val == rev: print(val , "is a palindrome") else: print(val , "is not a palindrome")
true
5dcf3b0e15341b299020736ce40374966b1551b4
mavrovski/PythonPrograming
/Programming Basics - Python/07AdvancedLoops/11EnterEvenNumber.py
247
4.1875
4
n = int while (bool): try: n = int(input("Enter even number:")) if n % 2 == 0: break print("The number is not even.") except: print("Invalid number!") print("Even number entered: {0}".format(n))
true
270a2af0e9dfb681db4ea02a82668efbbed5c1e5
spastorferrari/Python-R-Cheatbook
/Programming For Analytics/Week_09/w09_numpy.py
1,904
4.28125
4
import numpy as np # one dimensional array of numbers 1-8 myonedim = np.array(list(range(1,9))) # two dimensional array of numbers 1-3 and numbers 4-6 # we need a ton of parenthesis since it needs to be passed as tuple mytwodim = np.array((list(range(1,4)), list(range(4,7)))) # three dimensional array # a list with...
true
9a5a4b2adb70cc0ba6873638689cc50439b72b38
bhaskarnn9/Python_Coding_Exercises
/Level_2_Challenge_2.py
427
4.25
4
# PAPER DOLL: Given a string, return a string where for every character in the original there are three characters¶ def paper_doll(input_word): input_list = list(input_word) resultant_string = '' sb = [] for item in input_list: sb.append(item) sb.append(item) sb.append(item...
true
feff52c5605393300ac5b184fca1f190958b8b7a
bhaskarnn9/Python_Coding_Exercises
/Level_1_Challenge_3.py
651
4.125
4
# Given a sentence, return a sentence with the words reversed def reverse_words_in_sentence(input_sentence): sentence_with_words_reversed = '' word_list = [] word_list = input_sentence.split(' ') reversed_word_list = [] last_word_index = len(word_list) - 1 x = 0 while last_word_index > x: ...
true
5ebd8ba5dcfa6ed023e008401682b5b1986bc889
ajayganji/python_basics
/albums.py
958
4.46875
4
#This program shows how to use functions and while loops so that the user input data is stored in dictionary. def artist_info(artist_name,song_name,album_name=None,): if album_name: info = {'name':artist_name.title(),'song':song_name,'album':album_name.title(),} else: info = {'name':artist_name.title(),'song':son...
true
e13ce57b080dc11c50ffd36ca82975c5b06f95de
abhishekjee2411/python_for_qa_synechron
/for_loop.py
327
4.25
4
#print something 5 times for x in range(5): print("Something") #print numbers 0 to 5 for x in range(6): print(x) #print numbers 10 to 15 for x in range(10,16): print(x) #print multiples of 3 between 6 and 20 for x in range(6,20,3): print(x) #count down from 20 to 15 for x in range(20,14,-1): pr...
true
ad8e9a722d791cf991e3105387a26bdb932119e8
abhishekjee2411/python_for_qa_synechron
/sets_ops.py
429
4.1875
4
# A set is an ordered set of unique elements myfriends={"alam","madhav","modi","modi","sonia"} print(myfriends) mysistersfriends={"madhav","sonia","vijaya","hari"} print(myfriends.union(mysistersfriends)) print(myfriends - mysistersfriends) print(myfriends.intersection(mysistersfriends)) # You can use sets to remove ...
true
abd5ffa0ae3dd964485ceae3bdce04b2698256f2
kokubum/Data-Model
/attribute_access.py
2,231
4.5
4
class Test: teste=5 def __init__(self,number1,number2): print("Object created!") #To set this attribute, the __setattr__ will be called self.sum = number1+number2 #setattr(self,'sum',number1+number2) #__getattribute__ will be called always that you try to access an attribu...
true
c7bf05895d3639f0cb978a4196e4c34247ef4a3e
jcli1023/Python-Programs
/basic_programs/list_methods_example.py
645
4.125
4
# List methods work in place and not return a new list spam = ['cat', 'dog', 'bat'] spam.append('moose') spam.insert(1, 'chicken') for i in range(len(spam)): print(str(i) + '. ' + spam[i]) print() spam2 = ['cat', 'bat', 'rat', 'elephant', 'hat', 'cat'] spam2.remove('cat') for i in range(len(spam)): print(...
true
fdfe434f845e3835df9a8aa34b5caf58c1475f7a
AnupKumarPanwar/Python
/project_euler/problem_04/sol1.py
1,139
4.25
4
""" Problem: A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 x 99. Find the largest palindrome made from the product of two 3-digit numbers which is less than N. """ def solution(n): """Returns the largest palindrome made from the pr...
true
7f21639f69cc24f86438592ce70e01085aa657c4
AnupKumarPanwar/Python
/data_structures/binary_tree/basic_binary_tree.py
1,690
4.34375
4
class Node: # This is the Class Node with constructor that contains data variable to type data and left,right pointers. def __init__(self, data): self.data = data self.left = None self.right = None def display(tree): # In Order traversal of the tree if tree is None: return ...
true
260bca78d6e4f912efd52f592887db601be64074
AnupKumarPanwar/Python
/backtracking/minimax.py
998
4.1875
4
import math """ Minimax helps to achieve maximum score in a game by checking all possible moves depth is current depth in game tree. nodeIndex is index of current node in scores[]. if move is of maximizer return true else false leaves of game tree is stored in scores[] height is maximum height o...
true
eb5e1b7a7876d1fd95249e82a2cb207a8636291e
Bethany102082/web-caesar
/caesar.py
521
4.125
4
from helpers import alphabet_position, rotate_character def encrypt(text, rot): new_text = "" for letter in text: new_letter = rotate_character(letter, rot) new_text += new_letter return new_text def main(): secret_message = input("What's your secret message?") rotation_request =...
true
36768720a96c0610de0f9fb30ec82d3ceccd8f07
jyleong/DailyCodingProblems
/daily_coding_problem_221.py
1,224
4.1875
4
''' Let's define a "sevenish" number to be one which is either a power of 7, or the sum of unique powers of 7. The first few sevenish numbers are 1, 7, 8, 49, and so on. Create an algorithm to find the nth sevenish number. ''' import unittest def get_nth_sevenish(n): if n < 1: raise Exception('Invalid num...
true
2a70108c86c872dcc9b20e68e278c7ef8f6cbaba
jyleong/DailyCodingProblems
/daily_coding_problem_153.py
2,118
4.1875
4
''' Find an efficient algorithm to find the smallest distance (measured in number of words) between any two given words in a string. For example, given words "hello", and "world" and a text content of "dog cat hello cat dog dog hello cat world", return 1 because there's only one word "cat" in between the two words....
true
0ad7be9f22df801737c13a88aff1f2c4ffe1d966
jyleong/DailyCodingProblems
/daily_coding_problem_62.py
1,717
4.125
4
''' Given a 2D matrix of characters and a target word, write a function that returns whether the word can be found in the matrix by going left-to-right, or up-to-down. For example, given the following matrix: [['F', 'A', 'C', 'I'], ['O', 'B', 'Q', 'P'], ['A', 'N', 'O', 'B'], ['M', 'A', 'S', 'S']] and the target ...
true
6b361bf8eb475ae77e8d46d584c8263ad93c29e0
KristinArnall/Code-Wars-Exercises
/Python/8kyu.py
557
4.125
4
# # Even or odd # def even_or_odd(number): # if number % 2 == 0: # return "Even" # else: # return "Odd" # # given a number, find its opposite. # def opposite(number): # new_num = number*(-1) # return new_num # You get an array of numbers, return the sum of all of the positives ones. # def positive...
true
fec4cda0ff11bf96cb673e3c732b7046eb461baa
Maadaan/IW-pythonAssignment
/pythonAssignment/dataTypes/3rd.py
329
4.125
4
""" Write a Python program to get a string from a given string where all occurrences of its first char have been changed to '$', except the first char itself. Sample String : 'restart' Expected Result : 'resta$t' """ strings = 'restart' wordToBeReplaced = strings.replace(strings[0],'$') print(strings[0] + wordToBeRepl...
true
1379d8b2c706d85a9b2bad7c8bd39d927973d48f
Maadaan/IW-pythonAssignment
/pythonAssignment/functions/5th.py
339
4.375
4
""" Write a Python function to calculate the factorial of a number (a non-negative integer). The function accepts the number as an argument. """ def func(num): if num > 0: product = 1 for i in range(1, num+1): product = product * i return product else: return N...
true
fb6516e6fbd63c95e609cc521d70d0f4bb321362
Maadaan/IW-pythonAssignment
/pythonAssignment/functions/3rd.py
275
4.125
4
""" Write a Python function to multiply all the numbers in a list. Sample List : (8, 2, 3, -1, 7) Expected Output : -336 """ lists = [8, 2, 3, -1, 7] def func(item): product = 1 for num in item: product = product * num return product print(func(lists))
true
26503b3dde1908323ebb65a99cbcb3661bfed6da
Maadaan/IW-pythonAssignment
/pythonAssignment/dataTypes/8th.py
374
4.1875
4
""" Write a Python program to remove the nth index character from a nonempty string. """ string = 'linkein_park' removingIndex = 4 def func(word,index): if len(word) > 0: listOfWord = list(word) listOfWord.pop(index) return ''.join(listOfWord) else: raise AttributeError('St...
true
4e5b70899efa02446f06bb2730ee1dc1a53a7bfa
imayer95/software_quality
/app/res/algorithms/python/BFS.py
1,518
4.125
4
import random import sys import time def bfs2(graph, start): """ Implementation of the breadth first search algorithm. :param graph: The graph represented as a dictionary where each node has a list of children. :param start: The root of the graph. :return: """ visited = set() visited....
true
bc54e9ede93c10ce353e6b48fa1d51b4d55d102b
berkerpeksag/python-playground
/power.py
916
4.1875
4
""" This simple algorithm illustrates an important principle of divide and conquer. It always pays to divide a job as evenly as possible. This principle applies to real life as well. When `n` is not power of two, the problem cannot always be divided perfect evenly, but a difference of one element between the two sides...
true
4a3e3c387a40b819956711549829b806dd6bf828
anitalesi/SmartNinja
/lesson_8/calculator.py
439
4.25
4
x = float(input("Add a number")) y = float(input("Add another number ")) operation = str(input("Choose Operation: +, -, * or /")) while operation not in ("+","-","*","/"): print("Incorrect operator.") operation = str(input("Please choose from: +, -, *, /")) if operation == "+": print(x+y) ...
true
d22389b18e3fe992bf198d35a676acaea687ee80
rodoufu/challenges
/leetCode/design/ImplementQueueUsingStacks.py
1,316
4.25
4
# https://leetcode.com/problems/implement-queue-using-stacks/ class MyQueue: def __init__(self): """ Initialize your data structure here. """ self.data = [[], []] self.can_peek = False def push(self, x: int) -> None: """ Push element x to the back of queu...
true
8fe4450b324d0caf2522b97c94dc9b5a9f0f0cc9
walls00000/python101
/cipher/transposition.py
2,940
4.125
4
# Transposition Cipher Encryption # https://www.nostarch.com/crackingcodes/ import math def main(): # myMessage = "Common sense is not so common." myMessage = "Congratulations on the transposition cipher!" # file = input("Enter a filename: ") # handle = open(file, "r") # myMessage = handle.read() ...
true
4529a3ca3edbea00cd0623735e3154c71e0cb566
nclairesays/intro-python-hackforla
/class_one/02_strings.py
1,136
4.4375
4
# STRINGS # https://docs.python.org/3/tutorial/introduction.html#strings s = str(42) s # convert another data type into a string (casting) s = 'I like you' # examine a string s[0] # returns 'I' len(s) # returns 10 # string slicing like lists s[0:7] # returns 'I like ' s[6:] # returns 'you' s[-1] # returns...
true
400ce678e73bf9d87b4f23e763564bb38f4141ed
bhatkrishna/assignment2
/problem6.py
405
4.28125
4
# 6. Create a list with the names of friends and colleagues. Search for the # name ‘John’ using a for a loop. Print ‘not found’ if you didn't find it. _list= ['krishan', 'john', 'bikalpa', 'sanjaya', 'sita', 'suman'] for items in _list: flag= 0 if items=='john': print("the item is in index ", _list.in...
true
3106814c76cdfdad9d954dead78b9f753f2a6725
fawwad123/PIAIC
/AIC034159/Assignment/Assignment2.py
2,910
4.53125
5
# Write a program to calculate the percentage of a student and generate a report card of the student # This is the code to calculate the percentage of the student # Total marks of the total subjects totalMarks = 550 # User input of usr info and all the mark a student obtained name = input("Enter student name: ") roll...
true
a1b3d2c677f403e429b60b952c2a8f2b498f9dd0
syamilAbdillah/Snippets
/Python/InsertionSort.py
826
4.5
4
# Insertion Sort in Python, Time Complexity: O(n^2) def displayElements(arr, n): for el in arr: print(el, " ", end = "") print() def insertionSort(arr): for i in range(1, len(arr)): key = arr[i] j = i - 1 while j >= 0 and key < arr[j] : ...
true
4379c6d6db2e2abdc33b3981b53748bd277ee268
vipsinha/Python
/LinkedInLearning/1_Start.py
233
4.3125
4
print("Hello All: Find the max") x = int(input("Enter number 1: ")) y = int(input("Enter number 2: ")) z = int(input("Enter number 3: ")) print("Max of the three values is :") print(max(x,y,z)) input("Please press enter to exit")
true
45f52e71d39d5130a1efdeb52dab7892d9238d06
brianckeegan/Congress
/date_to_congress.py
938
4.15625
4
import datetime def convert_date_to_congress(date): ''' Takes a datetime.date object and returns an integer corresponding to the Congress in session on that date. Based on: http://en.wikipedia.org/wiki/List_of_United_States_Congresses ''' first = [datetime.date(i,3,4) for i in range(1789,1935,2)] ...
true
e0a9adb815c346eefba56b0870c63ec2dec71d96
thestacyharris/Python_I_Apps
/MyCalc/mycalc.py
2,814
4.15625
4
# === # Program Name: harris-lab1-assign1.py # Lab no: 1 # Description: Simple Python command line calculator app # Student: Stacy Harris # Date: 6/4/2020 # === title = "Simple Python Calculator" print(title) def main(): try: global num1 num1 = float(input("Enter the first numbe...
true
681e93d98d76f79066fb2491ccc49c70b96bca3b
lantzmw/LeetCode-Practice
/p3/solution.py
850
4.15625
4
""" There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). Example 1: nums1 = [1, 3] nums2 = [2] The median is 2.0 Example 2: nums1 = [1, 2] nums2 = [3, 4] The median is (2 + 3)/2 = 2.5 """ class So...
true
d555d5fac440e1604fe3be305d0f4817304d621f
noorah98/python1
/Session11.py
1,657
4.4375
4
# 1. Think of an object # Customer is object # name,phone,email,gender,address are attributes class Customer: pass cRef1 = Customer() # Object Construction Statement cRef2 = Customer() # Object Construction Statement cRef3 = cRef1 # Reference Copy Operation print(">> cRef1 is:", cRef1) print(">> ...
true
013d66894e931129c187e77a56f55f65be7aba7f
shashank-23995/Practice
/Python/Day_4/constants.py
481
4.375
4
# We define some options LOWER, UPPER, CAPITAL = 1, 2, 3 name = "jane" # We use our constants when assigning these values... print_style = UPPER # ...and when checking them if print_style==LOWER: print(name.lower()) elif print_style==UPPER: print(name.upper()) elif print-style==CAPITAL: print(name.capitalize()) el...
true
87f77bfef957d3cba093b342f40fa062b45335c1
LimaoC/projecteuler
/q07.py
433
4.15625
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? """ from support import is_prime def the_10001st_prime(): count = 2 current_num = 3 while count != 10001: current_num += 2 if is_prime(current_num)...
true
05d0d37d47d8e8c29bb9a2b117b5f90f6b9bff23
GZHOUW/Algorithm
/LeetCode Problems/Tree/Vertical Order Traversal of a Binary Tree.py
1,236
4.21875
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 ''' Algorithm: 1. Create a dict that stores nodes based on x coordinates 2. Traverse the tree recursively and comp...
true
80b9ca55c6b089912b83ac0284bc1590ffa5b54b
GZHOUW/Algorithm
/LeetCode Problems/Tree/Maximum Width of Binary Tree.py
2,591
4.34375
4
''' Given a binary tree, write a function to get the maximum width of the given tree. The width of a tree is the maximum width among all levels. The binary tree has the same structure as a full binary tree, but some nodes are null. The width of one level is defined as the length between the end-nodes (the leftmost an...
true
8649230d44b58f933b9250f072a671a4cfc39641
GZHOUW/Algorithm
/LeetCode Problems/Array/Prison Cells After N Days.py
2,403
4.25
4
''' There are 8 prison cells in a row, and each cell is either occupied or vacant. Each day, whether the cell is occupied or vacant changes according to the following rules: If a cell has two adjacent neighbors that are both occupied or both vacant, then the cell becomes occupied. Otherwise, it becomes vacant. (Note ...
true
36057b63bc5688ad322f077a79eb30bb079e55a7
GZHOUW/Algorithm
/LeetCode Problems/Array/Maximum Product Subarray.py
1,097
4.28125
4
''' Given an integer array nums, find the contiguous subarray within an array (containing at least one number) which has the largest product. Example 1: Input: [2,3,-2,4] Output: 6 Explanation: [2,3] has the largest product 6. Example 2: Input: [-2,0,-1] Output: 0 Explanation: The result cannot be 2, because [-2,-1...
true
c1eb4beb5fa4d40d18c463b4611dcfefc4bdcde6
GZHOUW/Algorithm
/LeetCode Problems/Linked List/Odd Even Linked List.py
1,479
4.125
4
''' Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes. You should try to do it in place. The program should run in O(1) space complexity and O(nodes) time complexity. Example 1: Input: 1->2->3->4->5...
true
5a4e7d7add40dcaa9cff187f5e9462a9b205744e
GZHOUW/Algorithm
/LeetCode Problems/Hash Table/Contiguous Array.py
1,702
4.21875
4
''' Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and 1. Example 1: Input: [0,1] Output: 2 Explanation: [0, 1] is the longest contiguous subarray with equal number of 0 and 1. Example 2: Input: [0,1,0] Output: 2 Explanation: [0, 1] (or [1, 0]) is a longest contiguous su...
true
5e72108845350ba2bfb454ccbbcc2512f49649fd
GZHOUW/Algorithm
/Sorting Algorithms/Bubble Sort.py
516
4.125
4
def BubbleSort(L): if len(L) <= 1: # must be sorted return L for i in range(len(L)): # every iteration of outer loop puts the next smallest number in place left = len(L) - 2 right = len(L) - 1 while left >= i: # 0:i elements are already sorted, no need to check if L[...
true
e5eebc234373dac3cba66f3a8d15b8c57a88b547
ClayPalmerOPHS/Y11-Python
/String Slicing Challenges02.py
252
4.1875
4
#String Slicing Challenges 02 #Clay Palmer forename = str(input("Enter your first name: ")) surname = str(input("Enter your second name: ")) fullName = forename + surname length = len(fullName) print(fullName) print("The length of your name is",length)
true
78d067f2d5b11f2006947a137e7c00ecb9d54bb2
AheleeBhattacharya/Local-Hack-Day-Share-2021
/Sort a List using lambda in Python.py
597
4.5
4
# Python code to sorting list # according to the column # sortarray function is defined def sortarray(array): for i in range(len(array[0])): # sorting array in ascending # order specific to column i, # here i is the column index sortedcolumn = sorted(array, key = lambda x:x[i]) # After sorting array...
true
052ccd05918ad8abf8cea4c18880b5fbf6ae7d5a
kkrawczyk5/Module-8---Boolean-and-Selections
/Problem 3 - list check.py
290
4.15625
4
#Created by Kamil Krawczyk #03/04/2020 #Problem 3 #This program takes a list and outputs if the number 5 is in the list or not def list_check(): the_list = [1,2,4,23,34,5,7,2,1,9,8,7] for x in the_list: if(x == 5): print("The number 5 is in this list") list_check()
true
164f8d4c2e8cd47c62f2e24ab61bc024a4ffaa44
Easytolearndemo/Practice_Python_code
/37.largest.py
283
4.28125
4
# Largest element in ana array from array import * a=array('i',[]) n=int(input("Enter how many element:")) for i in range(n): a.append(int(input("Enter the element:"))) big=a[0] for i in range(1,len(a)): if a[i]>big: big=a[i] print(f"The largest element is:{big}")
true
74d941079ec6beca35984e1f28be54a0d1408e8c
mitchell-frost/Python-Scripts
/random1.py
1,590
4.25
4
#importing the module import random # This is Q1. The function makes a list of 5 passes of the dice def RollFive(): list = [random.randint(1, 6) for i in range(5)] return list # this loop calls the function 7 times. It is part of Q1 #for i in range(7): # print(RollFive()) greater_22 = 0 #variable to keep count of...
true
ae9e02c70d40c1217cbdc75f82a92831275e65cb
MichalSl/Python_exercises
/binary_calc.py
685
4.25
4
def binaryToDecimal(): binary_number = input("Enter a binary number: ") binary_number_list = [int(x) for x in binary_number] # creating a list of binary digits of the binary number binary_number_list_reverse = binary_number_list[::-1] # reversing the list powers = [x for x in r...
true
60464ba4d4e6767d1b50f9c70e9c11b42e7a29e0
qiaoshun8888/PythonAlgPractice
/hw6_rodCuttingWithCost.py
2,391
4.21875
4
# coding=UTF-8 __author__ = 'johnqiao' ''' Given an initial rod of integer length m and a table that gives the values of rods with integer lengths from 1 to m, you can solve the rod cutting problem (computing the maximum value you can get after cutting) using dynamic programming. Now, suppose ...
true
33f39233b66b6dd22f3bfd4ebb62fb00333286cc
SpencerAxelrod/MinimumRanges
/minimum_ranges.py
1,303
4.46875
4
def find_min_ranges(ranges): """ Produces the minimum number of ranges required to represent the input list of ranges Args:    ranges: A list of ranges. A range is represented as a list with two items, an upper bound and lower bound Returns:    A list of the minimum ranges required. """ min_ranges = []...
true
26e4c40dd4ee7029cad454a5c3234265f759cee4
slushkovsky/fronter
/utils/shell.py
1,331
4.21875
4
def ask_yes_no(question, default=None): ''' Ask a yes/no question via raw_input() and return their answer. @param question <str> is a string that is presented to the user. @param default <bool, None> Is the presumed answer if the user just hits <Enter>. ...
true
910e81e7958402d1c149d01d52f3c875e0c56bd8
Heart8reak/CSPT15_HashTables_I_GP
/src/demos/demo2.py
1,729
4.53125
5
""" You've uncovered a secret alien language. To your surpise, the language is made up of all English lowercase letters. However, the alphabet is possibly in a different order (but is some permutation of English lowercase letters). You need to write a function that, given a sequence of words written in this secret lang...
true
df158f3234526846fe8f787357df10442ed03955
siqiaof/CS61A-Spring-2018
/disc/disc03.py
1,567
4.1875
4
# Constructor def tree(label, branches=[]): return [label] + list(branches) # Selectors def label(tree): return tree[0] def branches(tree): return tree[1:] # For convenience def is_leaf(tree): return not branches(tree) # 3.1 def all_labels(t): if is_leaf(t): return [lab...
true
68455052aea7f6313aab79bc425cd5ed4052f243
Aniket121397/Python
/Python/Basic Coding (Python)/GreatestOf2.py
247
4.28125
4
# Write a program to find the greatest of two numbers num1 = int(input("Enter a number: ")) num2 = int(input("Enter a number: ")) if num1 > num2: print("The number",num1,"is greater") else: print("The number",num2,"is greater")
true
a8c18f11651cd7052ad704a6305b8a75c1b196cb
AdrianoKim/ListaDeExerciciosPythonBrasilAdrianoKim
/w3schools/Comments.py
699
4.21875
4
# Comments starts with a #, and Python will ignore them: # Example: print("Hello, World!") # Comments can be placed at the end of a line, and Python will ignore the rest of the line: print("Hello, World!") #This is a comment # Python does not really have a syntax for multi line comments. # To add a multiline comment...
true
53f3d1c76d7bb7db93098858af3b7072f22de2d2
AdrianoKim/ListaDeExerciciosPythonBrasilAdrianoKim
/w3schools/Tuples Update.py
647
4.5
4
# Remove Items # Note: You cannot remove items in a tuple. # Tuples are unchangeable, so you cannot remove items from it, # but you can use the same workaround as we used for changing and adding tuple items: # Example # Convert the tuple into a list, remove "apple", and convert it back into a tuple: thistuple = ("ap...
true
c2fd169f5e941831ba43a5a46022560b09684add
AdrianoKim/ListaDeExerciciosPythonBrasilAdrianoKim
/w3schools/Sets Loop.py
201
4.71875
5
# Loop Items # You can loop through the set items by using a for loop: # Example # Loop through the set, and print the values: thisset = {"apple", "banana", "cherry"} for x in thisset: print(x)
true
45b2749276f878a5805cff7ce851be91214b9069
AmraniG/Python---Life-expectancy-GDP
/life_expectancy_gdp.py
2,874
4.1875
4
#For this project, you will analyze data on GDP and life expectancy from the World Health Organization and the World Bank to try and identify the relationship # between the GDP and life expectancy of six countries. # During this project, you will analyze, prepare, and plot data in order to answer questions in a mean...
true
95f9621efc0602f1113cf8c9076e4cca5d1613f5
kingssafy/til
/trash/pcc/tiy/7-3.py
227
4.1875
4
number = input("Enter any number you want: ") number = int(number) if number % 10 == 0: print("The number " + str(number) + " is a multiple of 10.") else: print("The number " + str(number) + " isn't a multiple of 10.")
true
b145861aba76336309e48250ee72f82142387d1d
georgeclm/python
/building a better calculator.py
458
4.40625
4
num1 = float(input("Enter the first number: ")) op = input("Enter operator: ") num2 = float(input("Enter the second number: ")) wrong = False if op == "+": result = num1 + num2 elif op == "-": result = num1 - num2 elif op == "/": result = num1 / num2 elif op == "*": result = num1 * num2 else...
true