blob_id
string
repo_name
string
path
string
length_bytes
int64
score
float64
int_score
int64
text
string
is_english
bool
330654c09eb6cbb1f913f2734102f51b225c8bcd
oneyedananas/learning
/for Loops.py
553
4.5
4
# performs code on each item in a list i.e. iteration. loops are a construct which can iterate through a list. # uses a while loop and a counter variable words = ["milda", "petr", "karel", "pavel"] counter = 0 max_index = len(words) - 1 # python starts counting from 0 so -1 is needed # print(max_index) now returns 3...
true
0685f623b4f9cb897a13d09f537b410e4bf76868
apranav19/FP_With_Python
/map_example.py
499
4.40625
4
""" Some simple examples that make use of the map function """ def get_name_lengths(names): """ Returns a list of name lengths """ return list(map(len, names)) def get_hashed_names(names): """ Returns a list of hashed names """ return list(map(hash, names)) if __name__ == '__main__': people = ["Mary", "Isla", ...
true
fe4ba27c40751233f94c4468944fd300c65ac1f8
luizpericolo/PythonProjects
/Text/count_words.py
793
4.46875
4
# Count Words in a String - Counts the number of individual words in a string. For added complexity read these strings in from a text file and generate a summary. string = '' while string.upper() != 'QUIT': string = raw_input("Enter a text to get a summary of strings or 'quit' to exit: ") if string.upper() != 'QUIT'...
true
54c7954e9b17b56aff806ec9f0ba48216e308f9a
IncapableFury/Triangle_Testing
/triangle.py
2,034
4.25
4
# -*- coding: utf-8 -*- """ Created on Thu Jan 14 13:44:00 2016 Updated Jan 21, 2018 The primary goal of this file is to demonstrate a simple python program to classify triangles @author: jrr @author: rk @ """ def classify_triangle(side1: int, side2: int, side3: int) -> str: """ Your correct code goes here....
true
d0935a48ad03c078bcb50b9adef38fa64e53df8f
cdueltgen/markov_exercise
/markov.py
1,053
4.28125
4
""" markov.py Reference text: section 13.8, how to think like a computer scientist Do markov analysis of a text and produce mimic text based off the original. Markov analysis consists of taking a text, and producing a mapping of prefixes to suffixes. A prefix consists of one or more words, and the next word to follo...
true
e4e4d1aa65cca834a26d27edd85da4a0543a96f7
NYU-Python-Intermediate-Legacy/jarnold-ipy-solutions
/jarnold-2.2.py
2,270
4.15625
4
#usr/bin/python2.7 import os import sys def unique_cities(cities): # get rid of empty items if cities.has_key(''): del cities[''] unique_cities = sorted(set(cities.keys())) return unique_cities def top_ten_countries(countries): # get rid of empty items if countries.has_key(''): del countries[''] ...
true
424c14cc7e7547593ae9bf715e78108b363d2cc3
ZuzaRatajczyk/Zookeeper
/Problems/Lucky ticket/task.py
466
4.125
4
# Save the input in this variable ticket = (input()) first_digit = int(ticket[0]) second_digit = int(ticket[1]) third_digit = int(ticket[2]) fourth_digit = int(ticket[3]) fifth_digit = int(ticket[4]) sixth_digit = int(ticket[5]) # Add up the digits for each half half1 = first_digit + second_digit + third_digit half2 ...
true
8da21b78fd90a65b70bb461f0370564724ab1dc8
ckabuloglu/interview_prep
/levelOrder.py
939
4.15625
4
''' Level Order Traversal Given a binary tree, print the nodes in order of levels (left to right for same level) ''' # Define the Tree structure class BSTNode: def __init__(self, val): self.val = val self.left = None self.right = None # Define the add method to add nodes to the tree def ad...
true
2c50bed4074123edcc2f4feab539c300a65071be
Garrison50/unit-2-brid
/2.3 Vol/SA.py
279
4.15625
4
def main(): import math radius = float(input("Enter the radius of the sphere")) volume = ((4/3) * math.pi * (pow(radius,3))) sa = (4 * math.pi * (pow(radius,2))) print ("The volume is:", round(volume,2)) print ("The surface area is:", round(sa,2)) main()
true
643730d15360ecc6c8e59db671e489a17932fe08
shakyaruchina/100DaysOfCode
/dayTen/calculator.py
1,182
4.25
4
#Calculator from art import logo #add function def add(n1,n2): return n1+n2 #subtract functuon def subtract(n1,n2): return n1-n2 #divide function def divide(n1,n2): return n1/n2 #multiply function def multiply(n1,n2): return n1*n2 #operation dictionary{key:value} operations = { "+":add, "-":s...
true
4f6d15c068cce2a7b00df861c2feea7d41a326cb
SamanehGhafouri/DataStructuresInPython
/doubly_linked_list.py
2,468
4.125
4
# Doubly Linked List # Advantages: over regular (singly) linked list # - Can iterate the list in either direction # - Can delete a node without iterating through the list (if given a pointer to the node) class Node: def __init__(self, d, n=None, p=None): self.data = d self.next_node = n ...
true
66352731d8b952a633dea499c56cc58903051b4d
nikitakumar2017/Assignment-4
/assignment-4.py
1,450
4.3125
4
#Q.1- Reverse the whole list using list methods. list1=[] n=int(input("Enter number of elements you want to enter in the list ")) for i in range(n): n=int(input("Enter element ")) list1.append(n) print(list(reversed(list1))) #Q.2- Print all the uppercase letters from a string. str1=input("Enter string ") for...
true
2abdecd0c2820f8db9ae2efc4252f9815c80d18d
bsdharshini/Python-exercise
/1)printprintprint.py
1,189
4.375
4
#https://www.codesdope.com/practice/python-printprintprint/ #1)Print anything you want on the screen. print("hello") # 2) Store three integers in x, y and z. Print their sum x=10 y=20 z=30 sum=x+y+z print(sum) #3) Store three integers in x, y and z. Print their product. x,y,z=10,20,30 print(x*y*z) #...
true
bf794f5e450f517f9aa56012b18298c471d68999
Kapiszko/Learn-Python
/ex11.py
426
4.15625
4
print("How old are you?", end=' ') age = int(input("Please give your age ")) print("How tall are you?", end=' ') height = int(input("Please give your height ")) print("How much do you weigh?", end=' ') weight = int(input("Please give your weight ")) print (f"So, you're {age} old, {height} tall and {weight} heavy.") s...
true
fc41dcd6953857498946355e64e58b32429fcc45
YashMistry1406/Competitve_Coding-
/sde problems/Array/sort color.py
1,119
4.15625
4
# Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, # with the colors in the order red, white, and blue. # We will use the integers 0, 1, and 2 to represent the color red, white, and blue, respectively. # You must solve this problem witho...
true
4a96f7c36e897f6af65eaa60077bd988d9b7e34b
serubirikenny/Shoppinlist2db
/shop.py
1,043
4.125
4
class ShoppingList(object): """class to represent a shopping list and CRUD methods""" def __init__(self, name): self.name = name self.items = {} def add_item(self, an_item): if an_item.name in self.items: self.items[an_item.name] += an_item.quantity else: ...
true
12682f41edb0a57e5774e5404b11b7a72c1698a8
aarushikool/CrypKool
/OTP.py
2,228
4.3125
4
from random import randint import matplotlib.pyplot as plt #string alphabet is declared here to convert ALPHABET into numerical values #ALPHABET[0] is a blank space ALPHABET = ' ABCDEFGHIJKLMNOPQRSTUVWXYZ' def encrypt(text, key): text= text.upper() cipher_text = '' for index, char in enumerate(text): ...
true
cc9caf4d73ee3d43b06d3698abc27888924ac923
garymorrissey/Programming-And-Scripting
/collatz.py
537
4.125
4
# Gary Morrissey, 11-02-2018 # The Collatz Conjecture program i = int(input("Please enter any integer:")) # Prompts you to choose a number, with the next term being obtained from the previous term while i > 1: if i % 2 == 0: i = i / 2 # If the previous term is even, the next term is one half the previo...
true
2b2bdc77c6e116371e56d5df4bb7699bc2dff31a
AmaanHUB/IntroPython
/variables_types/python_variables.py
847
4.34375
4
# How can we create a variable? # variable_name = value # creating a variable called name to store user name name = "Amaan" # declaring a String variable # creating a variable called age to store user age age = 23 # Integer # creating a variable called hourly_wage to store user hourly_wage hourly_wage = 15 # Intege...
true
19387eba9e667955c01c4fe19571af19b890c1d8
clowe88/Code_practicePy
/simple_cipher.py
277
4.15625
4
phrase = input("Enter a word or phrase to be encrypted: ") phrase_arr = [] finished_phrase = "" for i in phrase: phrase_arr.append(i) for x in phrase_arr: num = ord(x) cipher = chr(num + 12) finished_phrase += cipher print (finished_phrase)
true
087bc5cc5c04f905117e7950cfd64b1b927a01f9
manasmishracse/Selenium_WebDriver_With_Python
/PythonTesting/Demo Code/ReadFile.py
305
4.1875
4
# Reading a File Line by Line in Python and reverse it in o/p. lines = [] rev = "" file = open('File_Demo.txt', 'r') lines = file.readlines() print("{}{}".format("Content in File is ", lines)) for i in lines: rev = i + rev print("{}{}".format("Reversed Content of the File is:", rev)) file.close()
true
a7e708c106dc18cdd1b222f807dc6225cb2a2347
satyam-seth-learnings/machine_learning
/Machine Learning using Python(NIELIT Lucknow)/My Code/Assignments/Assignment-3(Day-6)/4.Circle.py
428
4.25
4
# Write a Python class named Circle constructed by a radius and two methods which will compute the area and the perimeter of a circle. class Circle: def __init__(self,r): self.radius=r def area(self): return 3.14*self.radius**2 def perimeter(self): return 2*3.14*self.radius c...
true
5aa478055b9109df4e9b32ddf801473d80399148
satyam-seth-learnings/machine_learning
/Machine Learning using Python(NIELIT Lucknow)/My Code/Assignments/Assignment-2(Day-4)/8.Find cube of all numbers of list and find minimum element and maximum element from resultant list.py
309
4.28125
4
# Using lambda and map calculate the cube of all numbers of a list and find minimum element and maximum element from the resultant list. l=[1,2,6,4,8,9,10] cubes=list(map(lambda x: x**3,l)) print(f'Cube of all numbers: {cubes}') print(f'Minimum element: {min(cubes)}') print(f'Maximum element: {max(cubes)}')
true
0afc2bd9622c2a0a32a3c369733d6df66d8284ce
roycrippen4/python_school
/Assignments/triangle.py
928
4.625
5
# Python Homework 1 - Triangles sides and angles # Roy Crippen # ENG 101 # Due 11/18/2019 # The goal of this code is to take three sides of a triangle from a user and to compute the angles of said triangle. from math import degrees from math import acos # First I will receive the sides of the triangle from the user s...
true
6b47c5254cee29f96045124913f14fee0f53b3c8
lazumbra/Educative-Data-Structures-in-Python-An-Interview-Refresher
/LinkedList/Doubly Linked Lists/main.py
1,673
4.125
4
from LinkedList import LinkedList from Node import Node def delete(lst, value): deleted = False if lst.is_empty(): print("List is Empty") return deleted current_node = lst.get_head() if current_node.data is value: # Point head to the next element of the first element ...
true
51f497fa15c6f77934f98cf1595b66cb7a455ae7
charleycodes/hb-code-challenges
/concatenate-lists-2-13.py
872
4.3125
4
# Whiteboard Easier # Concepts Lists def concat_lists(list1, list2): """Combine lists. >>> concat_lists([1, 2], [3, 4]) [1, 2, 3, 4] >>> concat_lists([], [1, 2]) [1, 2] >>> concat_lists([1, 2], []) [1, 2] >>> concat_lists([], []) [] """ ...
true
afaf0b4d56ec34e86b518d0b0f05a5b31c19e9dc
XiaoA/python-ds
/33_sum_range/sum_range.py
1,279
4.125
4
def sum_range(nums, start=0, end=None): """Return sum of numbers from start...end. - start: where to start (if not provided, start at list start) - end: where to stop (include this index) (if not provided, go through end) >>> nums = [1, 2, 3, 4] >>> sum_range(nums) 10 >>>...
true
2a5576f2f7f10af9f2f23ad68f7270d85e9ef6e3
Chaser/PythonHardWay
/Ex27/Ex27_MemorizingLogic.py
2,805
4.34375
4
def break_words(stuff): """This function will break up words for us.""" words = stuff.split(' ') return words def sort_words(words): """Sorts the words.""" return sorted(words) def print_first_word(words): """Prints the first word after popping it off.""" word = words.pop(0) ...
true
45fd466c0cfd03262a9baad12133103943aa88c6
sanket-k/Assignment_py
/python-files/Question 3.py
2,008
4.4375
4
# coding: utf-8 # ### Question 3 # ### Note: problem similar to Question 2 # Write a program which takes 2 digits, X,Y as input and generates a 2-dimensional array. The # element value in the i-th row and j-th column of the array should be i*j. # # Note: i=0,1.., X-1; j=0,1,¡ Y-1. # # #### Example # # Suppose th...
true
ab4216252416679138e20fa13c9abdb37f7c73cc
KalinHar/OOP-Python-SoftUni
/workshop/hash_table.py
2,142
4.21875
4
class HashTable: """"The HashTable should have an attribute called array of type: list, where all the values will be stored. Upon initialization the default length of the array should be 4. After each addition of an element if the HashTable gets too populated, double the length of the array ...
true
a352cb58f7c04e49769d48edab362c55e03a2142
karslio/PYCODERS
/Assignments-04-functions/11-equal_reverse.py
242
4.25
4
def equal_reverse(): word = input('enter a word') newString = word[::-1] if word == newString: return True else: return False print(equal_reverse()) # Ex: madam, tacocat, utrecht # Result: True, True, False
true
55aa5c2b12663d078a37ff58edcda05416d69f04
madisonstewart2018/quiz1
/main 6.py
1,184
4.46875
4
#this function uses the variables matrix and vector. def matVec(matrix, vector): ''' The function takes in a matrix with a vector, and for each element in one row multiplies by each number in the vector and then adds them together. Function returns a new vector. ''' new_x = [] for i in range(len(matrix)): ...
true
081346e448fc60eec12caf9bab5aca15080bb962
BrianClark1/Python-for-Everybody-Specialization
/Chapter 11/11.2.py
827
4.21875
4
#Looking inside of a file, Extracting numbers and summing them name = input("Enter file:") #Prompt User to input the file if len(name) < 1 : name = "RegexRealSum.txt" #Allows user to simply press enter to open specific file handle = open(name) #assigns the file to a variable name inp = handle.read() #Reads the entir...
true
f9ddc7d5c1236760550c5d868536c748d1769e88
nazhimkalam/Complete-Python-Crash-Couse-Tutorials-Available
/completed Tutorials/bubbleSort.py
706
4.28125
4
#The main difference between bubble sort and insertion sort is that #bubble sort performs sorting by checking the neighboring data elements and swapping them if they are in wrong order #while insertion sort performs sorting by transferring one element to a partially sorted array at a time. #BUBBLE SORT myList = [15,24...
true
b87526548062f13ae7e10e90185550b9c896cee5
nazhimkalam/Complete-Python-Crash-Couse-Tutorials-Available
/completed Tutorials/global, local, nonlocal scope variables.py
1,113
4.59375
5
#The nonlocal keyword is used to work with variables inside nested functions, #where the variable should not belong to the inner function. #Use the keyword nonlocal to declare that the variable is not local. #Example 01 (with nonlocal) def myfunc01(): x = "John" #x is 'John' def myfunc02(): nonlocal x ...
true
ee9e7af06d173872648edb0c4ae4ce925981a930
saketborse/Blink-to-Roll-Dice-with-Eye-Detection
/diceroll.py
648
4.15625
4
import random def dice(): # range of the values of a dice min_val = 1 max_val = 6 # to loop the rolling through user input roll_again = "yes" # loop while roll_again == "yes" or roll_again == "y": #print("Rolling The Dices...") #print("The Values are :") ...
true
56bfcf0cd7d2ffcca129085aa597ec7d19ca1b22
aandr26/Learning_Python
/Coursera/Week3/Week3b/Projects/format.py
1,239
4.21875
4
# Testing template for format function in "Stopwatch - The game" ################################################### # Student should add code for the format function here def format(t): ''' A = minutes, B = tens of seconds, C = seconds > tens of seconds D = remaining tens of seconds. A:BC:D '''...
true
20b6edc6c257810f00377bc18c4fb0c4d5fe7d3a
aandr26/Learning_Python
/Coursera/Week3/Week3b/Exercises/expanding_cricle.py
865
4.125
4
# Expanding circle by timer ################################################### # Student should add code where relevant to the following. import simplegui WIDTH = 200 HEIGHT = 200 radius = 1 # Timer handler def tick(): global radius global WIDTH radius += 2 # Draw handler def draw(canvas): ...
true
1da99068500ac43445324a856ac14ff1f7e1c626
rebel47/PythonInOneVideoByCodeWithHarry
/chapter2solutions.py
886
4.28125
4
# To add two numbers # a = int(input("Enter the first number: \n")) # b = int(input("Enter the second number: \n")) # print("Sum of first and second number is:",a+b) # To find the remainder # a = int(input("Enter the number whose remainder you want to know: \n")) # print("The reaminder of the given number is:", a%2) ...
true
a608c36a28981eb16358dfb74e1414d1b028aacb
rebel47/PythonInOneVideoByCodeWithHarry
/chapter3solutions.py
829
4.40625
4
# # Print user name with Good afternoon message # name = input("Enter your name:\n") # print("Good afternoon", name) # #Print the given name by adding user name # name = input("Enter the Candidate Name:\n") # date = input("Enter the Date:\n") # letter = '''Dear <|NAME|>, # You are selected!! # Date: <|DATE|>''' # le...
true
52deb61b876f65ec65d06c4285f7e34db66ccdec
arushss/Python_Task
/Task01.py
2,516
4.5
4
# Create three variables in a single line and assign different values to them and make sure their data types are different. # Like one is int, another one is float and the last one is a string. x, y, z = 10, 20.5, "Consultadd" print ("x is: ", x) print ("y is: ", y) print ("z is: ", z) # Create a variable of value ty...
true
2f60538072b1e817495b6a4df3036e4a06c72713
BoLindJensen/Reminder
/Python_Code/Snippets/Files/MoreFiles/Open.py
1,513
4.125
4
''' The function open() opens a file. file: path to file (required) mode: read/write/append, binary/text encoding: text encoding eg. utf-8. It is a good idea to always specify this, as you never know what other file systems use as their default Modes: 'r' Read 'w' Write 'x' eXclusive creation, fails if the file alre...
true
ec4d7456fbfaa7bef8bbe1244174b7c984ffd999
BoLindJensen/Reminder
/Python_Code/Snippets/Lists/List_Comprehension.py
225
4.59375
5
# https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions # L3 returns all elements of L1 not in L2. L1 = [1,2,6,8] L2 = [2,3,5,8] L3 = [x for x in L1 if x not in L2] print(L3) #L3 will contain [1, 6].
true
570d466855d3abeb761c3bb07e1f53628b2df264
BoLindJensen/Reminder
/Python_Code/Snippets/Lists/List_Comprehension2.py
950
4.34375
4
''' Python Comprehension works on list[], set{}, dictionaries{key:value} List Comprehension style is Declarative and Functional it is readable, expressive, and effective. [ expr(item) for item in items ] [ expr(item) for item in iterable ] [ expr(item) for item in iterable if predicate(item) ] ''' words = "What is ...
true
d31d9c60357120583f0fb35784016b5d561aef81
sgttwld/tensorflow-2-simple-examples
/1b_gradientdescent_gradient.py
831
4.15625
4
""" Example of gradient descent to find the minimum of a function using tensorflow 2.1 with explicit gradient calculation that allows further processing Author: Sebastian Gottwald Project: https://github.com/sgttwld/tensorflow-2.0-simple-examples """ import tensorflow as tf import numpy as np import os os.environ['TF...
true
9ca4f40c2b05a7da51e640000c6a37ca88bf91a8
suvratjain18/CAP930Autum
/23AugPractical.py
1,078
4.59375
5
# What Is Sets #collection of well defined things or elements #or # Unorderd collection of distinct hashable elements #In First Create a set s={1,2,3} print(s) print(type(s)) t={'M','K','R'} print(t) print(type(t)) # How you can declare Empty Set using below here # empty_set=set() # it will convert list to string belo...
true
661fe7a34a439278c3830a9b13f4b5f6b8d0521e
AnatoliKosarev/Python-beginner-course--Teclado-
/filesPython/fileImports/user_interactions/myfile.py
1,138
4.21875
4
print(__name__) """ The file that we run always has a __name__ variable with a value of "__main__". That is simply how Python tells us that we ran that file. Running code only in script mode Sometimes we want to include some code in a file, but we only want that code to run if we executed that file directly—and not i...
true
b0410a2b46b734f18da31834065151d53cd37a41
AnatoliKosarev/Python-beginner-course--Teclado-
/advancedPythonDevelopment/itertoolsCombinatoricIterators.py
2,369
4.84375
5
# permutations """ permutations is concerned with finding all of the possible orderings for a given collection of items. For example, if we have the string "ABC", permutations will find all of the ways we can reorder the letters in this string, so that each order is unique. """ from itertools import permutations p_1 =...
true
3814a7116033ae2935d0ef09c8d7fae42f29c027
AnatoliKosarev/Python-beginner-course--Teclado-
/advancedPythonDevelopment/namedTuple.py
524
4.1875
4
from collections import namedtuple Student = namedtuple("Student", ["name", "age", "faculty"]) names = ["John", "Steve", "Mary"] ages = [19, 20, 18] faculties = ["Politics", "Economics", "Engineering"] students = [ Student(*student_data) for student_data in zip(names, ages, faculties) ] print(students) old...
true
bb7ba363b2297d7d57b85e3c9b2cd9ce71147235
AnatoliKosarev/Python-beginner-course--Teclado-
/pythonFundamentals/zipFunction.py
2,299
4.65625
5
""" Much like range, zip is lazy, which means it only calculates the next value when we request it. We therefore can't print it directly, but we can convert it to something like a list if we want to see the output """ from itertools import zip_longest student_ids = (112343, 134555, 113826, 124888) names = ("mary", "Ri...
true
36c9c7f2a4f0f955a46fd85c4116897bfbf61143
AnatoliKosarev/Python-beginner-course--Teclado-
/pythonFundamentals/input.py
239
4.15625
4
my_name = "Bob" your_name = input("Enter your name: ") # always returns string print(f"Hello, {your_name}. My name is {my_name}") print() age = int(input("enter your age: ")) months = age * 12 print(f"you have lived for {months} months")
true
b012c287ee491ed19617ebc9ec1b5d82b89e3d10
AnatoliKosarev/Python-beginner-course--Teclado-
/pythonFundamentals/listComprehension.py
2,079
4.53125
5
# can be used with lists, tuples, sets, dictionaries numbers = [0, 1, 2, 3, 4] doubled_numbers1 = [] for number in numbers: doubled_numbers1.append(number * 2) print(doubled_numbers1) # same can be done with list comprehension which is much shorter doubled_numbers2 = [number2 * 2 for number2 in numbers] print(dou...
true
af12948c9b1f6161862ae5079d03bf8d3595e44e
jsdiuf/leetcode
/src/Powerful Integers.py
1,611
4.1875
4
""" @version: python3.5 @author: jsdiuf @contact: weichun713@foxmail.com @time: 2019/1/6 12:06 Given two non-negative integers x and y, an integer is powerful if it is equal to x^i + y^j for some integers i >= 0 and j >= 0. Return a list of all powerful integers that have value less than or equal to bound. You may re...
true
c167226fbfec1a0ecbf43cfcda87b6e51317e656
jsdiuf/leetcode
/src/N-ary Tree Preorder Traversal.py
835
4.15625
4
""" @version: python3.5 @author: jsdiuf @contact: weichun713@foxmail.com @time: 2018-10-23 9:19 Given an n-ary tree, return the preorder traversal of its nodes' values. For example, given a 3-ary tree: Return its preorder traversal as: [1,3,5,6,2,4]. Note: Recursive solution is trivial, could you do it iteratively?...
true
80c0e24423aa62f932ec85bb6c172dfac5c9244b
jsdiuf/leetcode
/src/Valid Parentheses.py
2,026
4.125
4
""" @version: python3.5 @author: jsdiuf @contact: weichun713@foxmail.com @time: 2018-8-3 9:47 Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets mus...
true
40d26a6f9730deb24c97e2793f492213daac4437
jsdiuf/leetcode
/src/Sort Array By Parity II.py
1,137
4.1875
4
""" @version: python3.5 @author: jsdiuf @contact: weichun713@foxmail.com @time: 2018-10-14 9:32 Given an array A of non-negative integers, half of the integers in A are odd, and half of the integers are even. Sort the array so that whenever A[i] is odd, i is odd; and whenever A[i] is even, i is even. You may return a...
true
15def978d14ace9dc60ae954f9c18cb1184acff7
sauerseb/Week-Two-Assignment
/program3.py
439
4.34375
4
# __author__ = Evan Sauers (sauerseb) # CIS-125-82A # program3.py # # This program prompts the user for a distance measured in kilometers, converts it to miles, and prints out the results. # K= kilometers # M= miles # Ask user for a distance in kilometers # Convert to miles # (K * .62) K = eval(input("Please enter...
true
3381cbb4e997978ffa139b47868fdb282a00a7db
langestefan/pyluhn
/luhn/luhn.py
1,094
4.25
4
"""Calculate checksum digit from any given number using Luhn algorithm.""" def create_luhn_checksum(number): """ Generates luhn checksum from any given integer number. :param number: Number input. Any integer number. :return: Calculated checksum digit """ str_number = str(number) n_digits ...
true
c0c74fe14d6ff278ee0bc0396d298cf903aa505f
kingsleyndiewo/codex-pythonium
/simple_caesar_cipher.py
806
4.40625
4
# A simple Caesar cipher # Author: Kingsley Robertovich # Caesar cipher is a type of substitution cipher in which each letter in the plaintext is # 'shifted' a certain number of places down the alphabet. In this example we use the ASCII # character set as our alphabet def encipher(clearText, offset = 5): cipherTex...
true
d4cabe574a786147dba2fbb9cee912e24a4a120d
adam-barnett/LeetCode
/unique-paths-ii.py
1,689
4.125
4
""" Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How many unique paths would there be? An obstacle and empty space is marked as 1 and 0 respectively in the grid. For example, There is one obstacle in the middle of a 3x3 grid as illustrated below. [[0,0,0], [0,1,0], [0,0,0]] The...
true
71a1e30327e58b46a8851048359e520621d8f088
miaoranren/calculator-2-exercise
/calculator.py
1,411
4.375
4
"""A prefix-notation calculator. Using the arithmetic.py file from Calculator Part 1, create the calculator program yourself in this file. """ from arithmetic import * while True: response = input("> ") tokens = response.split(' ') if tokens[0] == 'q': print("You will exit!") break ...
true
e8860d7c2095fa654b7e6ed28f9a60ce73931491
ptg251294/DailyCodingProblems
/ParanthesesImbalance.py
801
4.3125
4
# This problem was asked by Google. # # Given a string of parentheses, write a function to compute the minimum number of parentheses to be removed to make # the string valid (i.e. each open parenthesis is eventually closed). # # For example, given the string "()())()", you should return 1. Given the string ")(", you sh...
true
c56e83834fe1e889bd985dd43b7d9d62976554d2
ptg251294/DailyCodingProblems
/One2OneCharMapping.py
770
4.125
4
# This problem was asked by Bloomberg. # # Determine whether there exists a one-to-one character mapping from one string s1 to another s2. # # For example, given s1 = abc and s2 = bcd, return true since we can map a to b, b to c, and c to d. # # Given s1 = foo and s2 = bar, return false since the o cannot map to two ch...
true
1a4c2d8a5ff279c6b64d15c8f91670a2f83f956c
Giuco/data-structures-and-algorithms
/course-1-algorithmic-toolbox/week-1/1-max-pairwise-product/max_pairwise_product.py
796
4.15625
4
# python3 from typing import List def max_pairwise_product_original(numbers: List[int]) -> int: n = len(numbers) max_product = 0 for first in range(n): for second in range(first + 1, n): max_product = max(max_product, numbers[first] * numbers[second]) return max_product def max_...
true
03e1f167ce7bf0212b7556e2bb5ef2615ada7488
longm89/Python_practice
/513_find_bottom_left_tree_value.py
1,010
4.125
4
""" Given the root of a binary tree, return the leftmost value in the last row of the tree. """ # 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 findB...
true
a18b926704febe19ac9cd70081b09b3ea583fc98
ppysjp93/Effective-Computation-in-Physics
/Functions/lambdas.py
852
4.4375
4
# a simple lambda lambda x: x**2 # a lambda that is called after it is defined (lambda x, y=10: 2*x +y)(42) # just because it isi anonymous doesn't mean we can't give it a name! f = lambda: [x**2 for x in range(10)] print(f()) # a lambda as a dict value d = {'null': lambda *args, **kwargs: None} # lambda as a keywo...
true
5c01549c5e88fef47d466803ace0862a8f2331c2
ppysjp93/Effective-Computation-in-Physics
/Functions/generators.py
1,482
4.4375
4
def countdown(): yield 3 yield 2 yield 1 yield 'Blast off!' # generator g = countdown() next(g) x = next(g) print(x) y, z = next(g), next(g) print(z) for t in countdown(): if isinstance(t, int): message = "T-" + str(t) else: message = t print(message) # A more complex exam...
true
2c7926ba3280dbee2c3bb85dd16100a607c5374a
SDSS-Computing-Studies/004-booleans-ssm-0123
/task1.py
602
4.5
4
#! python3 """ Have the user input a number. Determine if the number is larger than 100 If it is, the output should read "The number is larger than 100" (2 points) Inputs: number Outputs: "The number is larger than 100" "The number is smaller than 100" "The number is 100" Example: Enter a number: 100 The number is...
true
02b0aeebab04235c4ebd3f1944e059e6faf581d2
kayartaya-vinod/2019_04_PYTHON_NXP
/examples/ex08.py
708
4.21875
4
''' More loop examples: Accept two numbers and print all primes between them ''' from ex07 import is_prime from ex06 import line def print_primes(start=1, end=100): while start <= end: if is_prime(start): print(start, end=', ') start += 1 print() line() # this function re-writes (overwrit...
true
058a01fa70d67c4322fa03dcb7b7ba1bfbf2d5b8
gabrielriqu3ti/GUI_Tkinter
/src/grid.py
381
4.15625
4
# -*- coding: utf-8 -*- """ Created on Mon Jan 13 22:24:18 2020 @author: gabri """ from tkinter import * root = Tk() # Creating Label Widget myLabel1 = Label(root, text = "Hello World!") myLabel2 = Label(root, text = "My name is Gabriel H Riqueti") # Shoving it onto the screen myLabel1.grid(row = 0...
true
8117eed08dbe2803db65510843a217ad1602808e
yhoang/rdm
/IRI/20170619_IRI.py
2,620
4.3125
4
#!/usr/bin/python3.5 ### printing methods # two ways to print in Python name = 'Florence' age = 73 print('%s is %d years old' % (name, age)) # common amongst many programming languages print('{} is {} years old'.format(name, age)) # perhaps more consistent with stardard Python syntax ### dictionary shopping_dict = {'...
true
fe7219d3dcbcb122404675c79678ec2aa46fec85
pascalmcme/myprogramming
/week5/lists.py
392
4.25
4
list = ["a","b","c"] #changeable and orderable collection tuple = (2,3) # not changeable print(type(list)) print(len(tuple)) list.append(99) print(list) newlist = list + [1] print(newlist) lista = [1,2,'a',True] # different data types in list print(lista[0]) print(lista[1:]) # 1 to end print(lista[::-1]) p...
true
88044fba92673eae63292c65aa63c804fc4fb041
ridersw/Karumanchi---Algorithms
/selectionSort.py
448
4.125
4
def selectionSort(arr): size = len(elements) for swi in range(len(elements)-1): minIndex = swi for swj in range(minIndex+1, size): if elements[swj] < elements[minIndex]: minIndex = swj if swi != minIndex: elements[swi], elements[minIndex] = elements[minIndex], elements[swi] if __...
true
e60d1d29e10422a69b0b867be7f849f4030e51fa
baishuai/leetcode
/algorithms/p151/151.py
300
4.125
4
# Given an input string, reverse the string word by word. # For example, # Given s = "the sky is blue", # return "blue is sky the". class Solution(object): def reverseWords(self, s): """ :type s: str :rtype: str """ return ' '.join(reversed(s.split()))
true
181f19fec56913372b5aa480dfea3e5d3c4c91b8
senseiakhanye/pythontraining
/section5/ifelseif.py
246
4.21875
4
isFound = True if (isFound): print("Is found") else: print("Is not found") #else if for python is different num = 2 if (num == 1): print("Number is one") elif (num == 2): print("Number if two") else: print("Number is three")
true
baca925b539e5fcc04be482c5fc8b27a6ff355eb
johnstinson99/introduction_to_python
/course materials/b05_matplotlib/d_sankey/sankey_example_1_defaults.py
1,070
4.34375
4
"""Demonstrate the Sankey class by producing three basic diagrams. """ import numpy as np import matplotlib.pyplot as plt from matplotlib.sankey import Sankey # Example 1 -- Mostly defaults # This demonstrates how to create a simple diagram by implicitly calling the # Sankey.add() method and by appending finish() to ...
true
1fc9ba256d1201e878b76e6d9419d162d0e9cd59
anuragpatilc/anu
/TAsk9_Rouletle_wheel_colors.py
992
4.375
4
# Program to decides the colour of the roulette wheel colour # Ask the user to select the packet between 0 to 36 packet = int(input('Enter the packet to tell the colour of that packet: ')) if packet < 0 or packet > 36: print('Please enter the number between 0 to 36') else: if packet == 0: print('...
true
83ccf65950e90bd1cf095c29e5b1c61b1d7a75d9
zeus911/sre
/leetcode/Search-for-a-Range.py
1,062
4.15625
4
#!/usr/bin/env python # -*- coding:utf-8 -*- __author__ = 'liuhui' ''' Given an array of integers sorted in ascending order, find the starting and ending position of a given target value. Your algorithm's runtime complexity must be in the order of O(log n). If the target is not found in the array, return [-1, -1]. ...
true
1dfd1b6ceeaaa4e18804ebdf96697fff2e494a25
mimichen226/GirlsWhoCode_SIP2018
/Python/Libraries/DONE_rock_paper_scissors.py
562
4.1875
4
########### Code for Rock Paper Scissors ############ import random gestures = ["scissors", "rock", "paper"] computer = random.choice(gestures) human = input("Rock, paper, scissors, SHOOT: ") human = human.lower().lstrip().rstrip() print("Computer chooses {}".format(computer.upper())) if computer == human: prin...
true
bff09661d3f94c924370978ec58eba596f184bcc
penelopy/interview_prep
/Basic_Algorithms/reverse_string.py
389
4.3125
4
""" Reverse a string""" def reverse_string(stringy): reversed_list = [] #strings are immutable, must convert to list and reverse reversed_list.extend(stringy) for i in range(len(reversed_list)/2): reversed_list[i], reversed_list[-1 - i] = reversed_list[-1 -i], reversed_list[i] print "".join(...
true
6507cb3071727a87c6c7309f92e7530b74fcc5a2
penelopy/interview_prep
/Trees_and_Graphs/tree_practice_file.py
1,262
4.25
4
"""NOTES AND PRACTICE FILE Ex. Binary Tree 1 / \ 2 3 Ex. Binary Search Tree 2 / \ 1 3 A binary search is performed on sorted data. With binary trees you use them to quickly look up numbers and compare them. They have quick insertion and lookup. """ class BinarySearchTree: def __init__...
true
2ee39e37dec9a9c5df1f70683a5a01d2a6935f09
ak14249/Python
/map_function.py
2,336
4.40625
4
print("Que: Write a map function that adds plus 5 to each item in the list.\n") lst1=[10, 20, 30, 40, 50, 60] lst2=list(map(lambda x:x+5,lst1)) print(lst2) print("\n=========================================================\n") print("Que: Write a map function that returns the squares of the items in the list.\n") l...
true
6098028a07d94854e273ca763d3ff1f566ea6c4d
karthikrk1/python_utils
/primeSieve.py
1,330
4.34375
4
#!/bin/python3 ''' This is an implementation of the sieve of eratosthenes. It is created for n=10^6 (Default Value). To use this in the program, please import this program as import primeSieve and call the default buildSieve method Author: Karthik Ramakrishnan ''' def buildSieve(N=1000000): ''' This function...
true
af8e0ab5c3cabbda9b75721c81492e285345c9d3
brianhoang7/6a
/find_median.py
940
4.28125
4
# Author: Brian Hoang # Date: 11/06/2019 # Description: function that takes list as parameter and finds the median of that list #function takes list as parameter def find_median(my_list): #sorts list from least to greatest my_list.sort() #distinguishes even number of items in list if len(my_list) % 2 ...
true
bbacdc29ca3d75eeaee34e1d9800e57b390bd83c
pastcyber/Tuplesweek4
/main.py
917
4.1875
4
value = (5, 4, 2000, 2.51, 8, 9, 151) def menu(): global value option = '' while(option != 6): print('*** Tuple example ***') print('1. Print Tuple ***') print('2. Loop over tuple') print('3. Copy Tuple') print('4. Convert to list') print('5. Sort Tuple') print('6. Exit ***') op...
true
70f84fb61188d4a12f42bc5ab4e90f190dde764b
YOOY/leetcode_notes
/problem/check_if_number_is_a_sum_of_powers_of_three.py
292
4.15625
4
# check if n can be formed by 3**0 + 3**1 + ... + 3**n # if any r equals to 2 it means we need 2 * (3 ** n) which should be false def checkPowersOfThree(n): while n > 1: n, r = divmod(n, 3) if r == 2: return False return True print(checkPowersOfThree(21))
true
07815b759c627172f59ac80c7bc403f6b9b48a90
Aditi-Billore/leetcode_may_challenge
/Week2/trie.py
2,258
4.1875
4
# Implementation of trie, prefix tree that stores string keys in tree. It is used for information retrieval. # class TrieNode: def __init__(self): self.children = [None] *26 self.isEndOfWord = False class Trie: def __init__(self): self.root = self.getNode() def getNode(self): ...
true
239d29e78ee6f68d72bcda0a08f25d62ee223b7d
ellezv/data_structures
/src/trie_tree.py
2,588
4.1875
4
"""Implementation of a Trie tree.""" class TrieTree(object): """.""" def __init__(self): """Instantiate a Trie tree.""" self._root = {} self._size = 0 def insert(self, iter): """Insert a string in the trie tree.""" if type(iter) is str: if not self.con...
true
20e60f62e4865b7a1beb1cdd67330159ebbba35c
LesterZ819/PythonProTips
/PythonBasics/Lists/CreatingLists.py
534
4.15625
4
#You can create a list of values by putting them in [brackets] and assigning them a variable. #For example: varialble = [item1, item2, item3, item4] #lists can contain any time of value, or multiple value types #Example list containing floats or real numbers. float = [1.25, 15.99, 21.33] #Example of a list con...
true
9f13a8c2f6f5d0f9095da83f175c15a51108096c
LukeBecker15/learn-arcade-work
/Lab 06 - Text Adventure/lab_06.py
2,656
4.15625
4
class Room: def __init__(self, description, north, south, east, west): self.description = description self.north = north self.south = south self.east = east self.west = west def main(): room_list = [] room = Room("You are in the entrance to the Clue house.\nThe p...
true
183d3360519f1935140cefd8830662d0f168e6ae
DhirajAmbure/MachineLearningProjects
/PythonPracticePrograms/factorialOfNumber.py
1,225
4.28125
4
import math as m def findfact(number): if number == 1: return number elif number != 0: return number * findfact(number - 1) number = int(input("Enter number to find Factorial: ")) if number < 0: print("factorial can not be found for negative numbers") elif number ==0: ...
true
18a845aa39833a9b137bd19759c543a8a77054b6
Ladydiana/LearnPython
/ListComprehensions.py
959
4.15625
4
# -*- coding: utf-8 -*- """ LIST COMPREHENSIONS """ #capitalized_cities = [city.title() for city in cities] squares = [x**2 for x in range(9) if x % 2 == 0] print(squares) #If you would like to add else, you have to move the conditionals to the beginning of the listcomp squares = [x**2 if x % 2 == 0 else x ...
true
e5f63dd75eadec1499cb15037c3b4623ace06b76
abhi472/Pluralsight
/Chapter5/classes.py
1,035
4.1875
4
students = [] class Student: school_name = "Sumermal Jain Public School" # this is similar to a static variable but unlike java we do not need to have a static class for static variables we # can have a class instance just like school_name for static call of it ...
true
62eadc4c3eb829a71a0a2fd24282da4a2c8f3232
abhi472/Pluralsight
/Chapter3/rangeLoop.py
444
4.375
4
x = 0 for index in range(10): # here range creates a list of size 10(argument that has been passed) x += 10 print("The value of X is {0}".format(x)) for index in range(5, 10): # two args mean list start from 5 and goes till 9 x += 10 print("The value of X is {0}".format(x)) for index in range(5, 10,...
true
80b8be8ba4fabddfcffaf7d8a69039c83679938f
JubindraKc/python_assignment_dec15
/#4_firstname_lastname_split.py
503
4.28125
4
def full_name(): print("your first name is ", first_name) print("your last name is ", last_name) choice = input("will you include your middle name? y/n\n") name = input("please enter your full name separated with whitespace\n") if choice == 'y': first_name, last_name, middle_name = name.split(" ...
true
48d8c9acfbbe437a075f8850b40559cc5a7d52d7
simonechen/PythonStartUp
/ex1.py
407
4.1875
4
# print("Hello World!") # print("Hello Again") # print("I like typing this.") # print("This is fun.") # print("Yay! Pringting.") # print("I'd much rather you 'not'.") print('I "said" do not touch this.') # ' "" ' print("I'm back.") # Terminate print("-how to make my script print only one of the lines?") print("-one way...
true
57629ce5b3adbfeb89b532c2b2af3b4977815c26
queeniekwan/mis3640
/session13/set_demo.py
540
4.3125
4
def unique_letters(word): unique_letters = [] for letter in word: if letter not in unique_letters: unique_letters.append(letter) return unique_letters print(unique_letters('bookkeeper')) # set is a function and type that returns unique elements in an item word = 'bookkeeper' s = set(w...
true
4babb313798da7167ba3ffbf63c6ce25ee2528c5
sayaliupasani1/Learning_Python
/basic_codes/list1.py
899
4.15625
4
fruits = ["Mango", "Apple", "Banana", "Chickoo", "Custard Apple", "Strawberry"] vegetables = ["Carrots", "Spinach", "Onion", "Kale", "Potato", "Capsicum", "Lettuce"] print (type(fruits)) print(fruits) #fruits.extend(vegetables) #print(fruits) #fruits.extend(vegetables[1]) print (fruits) fruits.extend(vegetables[1:3]) ...
true
7693ec8848f94f4375fa79e2d216744c71d4f56f
michaelpeng/anagramsgalore
/anagramlist.py
1,251
4.3125
4
""" Given a list of strings, tell which items are anagrams in the list, which ones are not ["scare", "sharp", "acres", "cares", "ho", "bob", "shoes", "harps", "oh"] return list of lists, each list grouping anagrams together """ """ Function to check two strings are anagrams of each other 'scare' 'acres' True """ de...
true
9d6eaa66b5e3e24818e50cadbbbba75e76a5ca73
ramlingamahesh/python_programs
/conditionsandloops/Sumof_NaturalNumbers.py
615
4.21875
4
num = int(input("Enter a number: ")) if num < 0: print("Enter a positive number") else: sum = 0 # use while loop to iterate un till zero while (num > 0): sum += num num -= 1 print("The sum is", sum) # 2 Python Program - Find Sum of Natural Numbers print("Enter '0' for exi...
true