blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
a7dc638df6ac53494899c2efbbf822bfdecc1591 | bdieu178/codewars-solns | /codewars-solns/python/FindTheOddInt.py | 400 | 4.125 | 4 |
"""
Given an array, find the int that appears an odd number of times.
There will always be only one integer that appears an odd number of times.
"""
#by Bryan Dieudonne
def find_it(seq):
odd_set = set(range(1,len(seq),2))
#even_set = set(range(0,len(seq),2))
for num2 in seq:
if seq.count(num2) in... | true |
66195bb93f5514fbe43bb8345f44519590b97d67 | rosspeckomplekt/interpersonal | /interpersonal/classes/interaction.py | 1,859 | 4.40625 | 4 | """
An Interaction describes the interaction between
two Persons
"""
class Interaction:
"""
An Interaction describes the interaction between
two Persons
"""
def __init__(self, person_a, person_b):
"""
Initialize an Interaction object for two Persons
So we can compute the v... | true |
26144ff76984d44a0de08f820e4c8d480da471f9 | Blckkovu/Python-Crash-Course-By-Eric-Matthes | /Python_work/Chapter 4 Working with List/List_Comprehension_Exerice.py | 778 | 4.3125 | 4 | #Exercise 4.3 count to 20 to print the numbers 1 to 20 inclusive
for numbers in range(1,21):
print(numbers)
#exercise 4.4 make a list of numbers from one to one million
Digits=[]
for value in range(1, 100):
digit= value
Digits.append(digit)
print(Digits)
#exercise 4.5 Make a list of odd_numbers
odd_number... | true |
46ae0cbd94ef9cfe3d7db2672a7b3fdb7387c420 | zstall/PythonProjects | /Automate the Boring Stuff/Chapter 5/Game Inventory Dictionary.py | 952 | 4.15625 | 4 | '''
Inventory Dictionary
Chapter 5 Pg. 120
Practice printing all the key and values of a dictionary:
This is a 'video game' inventory, and there is a method that
will print out all keys and values.
'''
import pprint
stuff = {'rope': 1, 'torch': 6, 'gold coin': 42, 'dagger': 1, 'arrow': 12}
dragonLoot = ['gold coin... | true |
1845d484d65c3d093709a18661e3831f02dfe43a | jmbarrie/nth-puzzle-py | /puzzle.py | 2,688 | 4.1875 | 4 | class Puzzle:
def __init__(self):
puzzle = None
def get_puzzle(self):
"""
Returns the current puzzle.
"""
return self.puzzle
def set_puzzle(self, puzzle_index1, puzzle_index2, new_puzzle_value):
"""
Sets the value of the puzzle
Args:
... | true |
14adc1395c2aeee017807dea90e51c51843db6fe | adanque/Validating-Accuracy-and-Loss-for-Deep-Learning | /run_NGram_Tokenization.py | 618 | 4.25 | 4 | """
Author: Alan Danque
Date: 20210128
Class: DSC 650
Exercise: 10.1.b
Purpose: Implement an `ngram` function that splits tokens into N-grams.
"""
import string
import nltk
def ngram(paragraph, n):
# Split the sentence by spaces
words = paragraph.split()
# Remove punctuation
table =... | true |
c87a2c0e8852951280f80560a908687fe6520443 | physmath17/primes | /Sieve_of_Eratosthenes.py | 663 | 4.125 | 4 | import math
val = input("Enter the number to be verified:")
n = int(val)
def SieveOfEratosthenes(m):
# create a boolean array upto m+1 with all entries true, if a number l is not prime prime[l] will be false
prime = [True for i in range(m+1)]
p = 2
while(p*p <= m):
# if prime[p] is not... | true |
3223a44a65e1e23339b818f7f408debd9aa44061 | elbryant/More-reading-and-writing | /ex15/ex15.py | 692 | 4.5 | 4 | #imports arguments
from sys import argv
#arguments used are script name and file name
script, filename = argv
#variable text is set to open the filename put in the arguments
txt = open(filename)
#it prints out the file name based on what was input
print "Here's your file %r:" % filename
#the system then reads the fi... | true |
046cf1a29e0eb4086d6c1259ee38eabd21fb69eb | pjrule/math87-final | /person/lostperson.py | 1,209 | 4.25 | 4 | import abc
class LostPerson(abc.ABC):
"""
A Lost Person is exactly what you would imagine - someone who is lost.
In our simulation, a lost person moves once per time step. At each time
step, he may move one or more units in any direction,
starting from his current location. Where exactly he moves ... | true |
c2d933e95360096ca4dd9e5b5ae43d88bf12d98a | pjrule/math87-final | /person/searcher.py | 1,464 | 4.4375 | 4 | import abc
class Searcher(abc.ABC):
"""
A searcher is someone who is looking for the lost person.
Just like the lost persons, each searcher may move once in a given turn,
and his movement is given by the underlying implementation. Searchers
will likely rely upon some model of how the lost person
... | true |
b3f657ec60d4ca40ba577d47db7e858b25c1363c | sumeet0420/100-days-python | /day18/01_basic_shapes.py | 723 | 4.3125 | 4 | # This is a sample Python script.
from turtle import Turtle, Screen
turtle = Turtle()
turtle.shape("turtle")
turtle.color("red")
##Draw a square
for _ in range(4):
turtle.forward(50)
turtle.right(90)
##Triangle
for _ in range(3):
turtle.forward(50)
turtle.right(90)
turtle.right(30)
turtle.up()
... | true |
71bba7d1d25862d29ac3d8acdc98d43179e80f6a | Hemangi3598/chap-10_p1 | /p1.py | 248 | 4.21875 | 4 | # wapp to accept as input integers
# print if the number is even or odd
print("welcome")
num = int(input(" enter an integer "))
if num % 2 == 0:
msg = "even"
else:
msg = "odd"
print(msg)
print("bye")
# without any exception handling | true |
37797497365526c9b40269ab128289bfb356770f | cnzh2020/30daysofpython-practice | /day_5/day5.py | 2,385 | 4.3125 | 4 |
# Exercises: Level 1
#Declare an empty list
# Declare a list with more than 5 items
#Find the length of your list
#Get the first item, the middle item and the last item of the list
#Declare a list called mixed_data_types, put your(name, age, height, marital status, address)
#Declare a list variable named it_comp... | true |
b6d7f2bb0a350603094975a35f6187caf2e94db4 | er-aditi/Learning-Python | /List Working Programs/List_Multiple_Threes.py | 237 | 4.3125 | 4 | print("It is table of 3:")
for value in range(1, 11):
data = value * 3
print("3 * " + str(value) + " = " + str(data))
num = int(input("Enter number: "))
for value in range(1, 11):
print(num, "*", value, "=", num * value)
| true |
fef166a1b1209874d026f2cf22647976ca55b75d | ggasmithh/ambient_intelligence_labs | /python-lab2/ex2.py | 606 | 4.125 | 4 |
#populate the dictionaries
task1 = {"todo": "call John for AmI project organization", "urgent": True}
task2 = {"todo": "buy a new mouse", "urgent": True}
task3 = {"todo": "find a present for Angelina's birthday", "urgent": False}
task4 = {"todo": "organize mega party (last week of April)", "urgent": False}
task5 = {"... | true |
5c65de57c07996977a54cc3df29d7a338e6ca0c2 | ratherfrances/trialphaseone001 | /02.py | 235 | 4.1875 | 4 |
#count the numbers of numbers in a list
def count(values):
counter = 0
for i in values:
if i == 2:
counter += 1
return counter
some_list = [7,7,2,4,2,2,2,2]
how_many = count(some_list)
print(how_many) | true |
749ebb33356adb897f3c945b626e5bf602d0b9dc | bradger68/Coding-Dojos | /Encryption-Dojo.py | 1,113 | 4.125 | 4 | """Problem Description
Given an alphabet decryption key like the one below, create a program that can crack any message using the decryption key."""
alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
abcs = "abcdefghijklmnopqrst... | true |
3e59f97243264672cda6cbfe64eebcdda132cec4 | ahmad-elkhawaldeh/ICS3U-Unit4-01-python | /loop.py | 608 | 4.25 | 4 | #!/usr/bin/env python3
# Created by: Ahmad El-khawaldeh
# Created on: Dec 2020
# This program uses a while loop
def main():
# input
positive_integer = print(" Enter how many times to repeat ")
positive_string = input("Enter Here plz : ")
loop_counter = 0
# process & output
try:
pos... | true |
43d1e9724a6cd7e687d7fff3dabbca353bff647e | anulkar/python-challenge | /PyParagraph/main.py | 1,037 | 4.34375 | 4 | # ===================================================================
# PYTHON HOMEWORK - PyParagraph
# GT DATA SCIENCE BOOTCAMP
# PROGRAMMED BY: ATUL NULKAR
# Date: JANUARY 2020
# ===================================================================
# This is the Main Python script to run for the PyParagraph analysis.
#... | true |
7d01963b43e212f2111ce01f79af38e0da96968a | davidvalles007/ContestCoding-Solutions | /magic7.py | 481 | 4.15625 | 4 | ## Author : David Valles
## Date : 03/03/2014
## Solution : 0
n=[0,1]
def generate_fibonacci(num1,num2):
if str(num1+num2)[0] == "7":
n.append((num1+num2))
print "The third digit of the smallest Fibonacci number which has a first digit of 7 is ", str(n[-1])[2]
... | true |
441e754bc2e9fa20ef150206e3df981e4d09219e | JohnMDCarroll/LearningPython | /Exercise_Eleven_Check_Primality.py | 708 | 4.28125 | 4 | '''
Ask the user for a number and determine whether the number is prime or not.
(For those who have forgotten, a prime number is a number that has no divisors.).
You can (and should!) use your answer to Exercise 4 to help you.
Take this opportunity to practice using functions, described below.
'''
num = int(input('Ins... | true |
846e0d89c165f9bf6633ad4e8c6c2b4fa7f4f2d9 | ToddZenger/PHYS19a | /challenge/challenge-00-00.py | 1,425 | 4.28125 | 4 | """
Author: Todd Zenger, Brandeis University
The purpose of this code is to print out
zeros of a quadratic function
"""
# Side note, I realize that you can make a function for this, but I'm
# keeping this very basic for now
a = 1
b = 2.1
c = -3
x1 = (-b + (b**2 - 4*a*c)**(1/2))/(2*a)
x2 = (-b - (b**2 - 4*a*c)**(1/2)... | true |
55bdad5976aab8dfb3ab6a6938f385ed53617760 | OldKalash7/CiphersProject | /src/ReverseCipher.py | 509 | 4.1875 | 4 | # This cipher takes a string and encrypts it turning it around
import pyperclip
def main():
message = ''
print('ENTER A STRING TO ENCRYPT: ')
message = str(input())
print('THIS IS YOUR MESSAGE ENCRYPTED, COPIED TO CLIPBOARD')
print(reversecipher(message))
def reversecipher(message):
encrypt... | true |
c7d92faa3acae56dacaec2575cba2ca7d8238c0b | Jparedes20/python_work | /squares.py | 884 | 4.46875 | 4 | #print the squares of a list of numbers
#define the list
_squares=[]
_values=list(range(1,21))
print("\nWe print a list of 20 numbers: \n"+str(_values))
#next loop will create the square of each number and will be appended to the list
for value in _values:
_squares.append(value**2)
print("\nWe print the squares of... | true |
831184ffb8435f4b5112614b9af5858d7a2288d9 | WillLuong97/Linked-List | /copyListRandomPointer.py | 2,916 | 4.125 | 4 | #python3 implementation of leetcode 138. Copy List with Random Pointer
#Problem statement:
'''
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.
Return a deep copy of the list.
The Linked List is represented in the input/output as a li... | true |
2e95b1adacf391d32c67da7bb97f2560aa1bbf9e | tatumalenko/algorithm-time | /2018-02-07/daily_temperatures.py | 1,017 | 4.34375 | 4 | # 739. Daily Temperatures
# Given a list of daily temperatures, produce a list that, for each day in
# the input, tells you how many days you would have to wait until a warmer
# temperature. If there is no future day for which this is possible, put 0 instead.
# For example, given the list temperatures = [73, 74, 75, 71... | true |
d02cf719b79e33c508fb926e9b7e38b364db4fcd | jacyyang04/Learn-Python-the-Hard-Way | /ex7.py | 643 | 4.34375 | 4 | #more printing from Learn Python the Hard Way
#sets variable equal to days of the week
days = "Mon Tue Wed Thur Fri Sat Sun"
#sets variable to the months with a new line for each month
months = "\nJan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug\nSept\nOct\nNov\nDec"
print("Here are the days: ", days)
print("Here are the month... | true |
700a82e58a7707ca2cb0dc14bafb18e4a727e4bf | jacyyang04/Learn-Python-the-Hard-Way | /ex11.py | 975 | 4.21875 | 4 | #modules is the same as libraries
#importing modules to this script
#argv holds the argument I pass to python
from sys import argv
#unpacks argv and assigns variables
script, first, second, third, fourth = argv
#can set variables up as raw_input() but would need to make sure
#in terminal, run it as:
#python3 ex11.py... | true |
79aef0118f5e68c75a8bd183fc03255326a62093 | emuro7/learn-python | /zen-eo.py | 1,016 | 4.1875 | 4 | import this
print("\n")#Skip a line
#Python basic data types
print("Python basic data types\n")
#Boolean
bool_t = True
bool_f = False
#Number
#Float
flt = 0.5
#Interger
num = 35
string = "Hello world"
#Some data types are either mutable or immutable
#Mutable means that the datatype can me m... | true |
46654e2236d2a7ec249e16df19e638cb8181a2f1 | sathvik-dhanya/python-programming-masterclass | /Section9_Dictionaries_Sets/dictionary1.py | 2,491 | 4.1875 | 4 | #!/usr/bin/env python3
"""
Modify the program so that the exits is a dictionary rather than a list,
with the keys being the numbers of the locations and the values being
dictionaries holding the exits (as they do at present). No change should
be needed to the actual code.
Once that is working, create another dictiona... | true |
2cddc7e70d96a836e0ef587d77da9ffa0716482f | sathvik-dhanya/python-programming-masterclass | /Section13_DBs/contacts.py | 829 | 4.4375 | 4 | #!/usr/bin/env python3
"""
Example for SQL in python
"""
import sqlite3
db = sqlite3.connect("contacts.sqlite")
db.execute("CREATE TABLE IF NOT EXISTS contacts (name TEXT, phone INTEGER, email TEXT)")
db.execute("INSERT INTO contacts(name, phone, email) VALUES('Tim', 6545678, 'tim@email.com')")
db.execute("INSERT IN... | true |
33dfbfa574f4b5980cf31b6e40956267499ac684 | reshmastadas/Machine_Learning | /Common_Functions/EDA/null_values.py | 971 | 4.1875 | 4 | import pandas as pd
def find_null_percent(df):
'''
Purpose:
Function to find % of null values in each column of a dataframe.
Input:
df: Dataframe.
Returns:
null_df: a dataframe with % of null values.
Imports:
import pandas as pd
Author: Reshma Tadas
'''
null_df = pd.DataFrame(df.isnull().sum()).reset_i... | true |
3c2d80b827853bf05c41635cfa2bb252a77f2a40 | ashleefeng/qbb2017-answers | /day2-morning/03-types.py | 613 | 4.15625 | 4 | #!/usr/bin/env python
print "Basic types..."
a_string = "This is a string"
an_integer = 7
int_to_str = str(an_integer)
a_real = 5.689
string_to_real = float("5.668")
truthy = True
falsy = False
for value in a_string, an_integer, a_real, truthy, falsy:
print value, type(value)
print "Lists and tuples"
a_list = [1... | true |
5a03cf6a51cb82092c5893c798e39fa215be2e9b | Ultenhofen/Sorting-Algorithms | /mergeSort.py | 1,335 | 4.15625 | 4 | from datetime import datetime
from timeit import default_timer as timer
def mergeSort(list):
if len(list) > 1:
m = len(list)//2 # Determine the midpoint of the list
Left = list[:m] # Then split the list into two halves
Rght = list[m:... | true |
fe0c65e6c220fe64851190821b18615cc7309b74 | niksfred/SoftUni_Fundamentals | /Functions_exercise/palindrome_integers.py | 321 | 4.21875 | 4 | def palindrome(numbers_string):
numbers_list = numbers_string.split(", ")
for number in numbers_list:
reversed_number ="".join(reversed(number))
if number == reversed_number:
print("True")
else:
print("False")
numbers_string = input()
palindrome(numbers_string)
... | true |
33703fa66bc1111940b91e017dc249640ece8eee | MirouHsr/one-million-arab-coders | /project/test.py | 2,263 | 4.4375 | 4 | # lesson 5: variables & strings
#we can use variable to define something like an int number or string or array
#syntax: var_name = expression ..
age = 23
days_of_year = 365.25
hours_of_sleep = 7
age_in_days = age * days_of_year
sleep_hours_in_life = age_in_days * hours_of_sleep
awake_hours_in_life = (age_in_days * 24... | true |
36806298597b23a57a45afcf94b1771f36ae4560 | debaonline4u/Python_Programming | /arrays_in_python/method_array_1.py | 820 | 4.28125 | 4 | # Python program to understand various methods of array class.
from array import *
arr = array('i', [10, 20, 30, 40, 50, 60, 70]) # Creating an array.
print('Original Array: ', arr)
# append 30 to the array
arr.append(30)
arr.append(60)
print('After appending 30 and 60: ', arr)
# insert 999 at position number 1 ... | true |
6affe16c2e1a39601d1e086763094dd3cf020142 | debaonline4u/Python_Programming | /arrays_in_python/linear_search.py | 811 | 4.1875 | 4 | # Python program to implement Linear Search.
from array import *
arr = array('i', []) # Creating an empty array.
print('How many elements you want to enter: ', end='')
n = int(input())
for i in range(n):
print('Enter elements: ', end='')
arr.append(int(input()))
print('Original Array: ', arr)
s = int(inp... | true |
56141ddfbbd276d0d440eb5d555e1a350d28063a | debaonline4u/Python_Programming | /string_functions_in_python/string_Template_with_list.py | 537 | 4.25 | 4 | # program to demonstrate string template for printing values in list.
from string import Template
# make a list of student_name and mark for students.
students=[('Ram',40),('Joshi',75),('Karan',55)]
#creating the basic structure to print the student name and their marks.
t=Template("Hi $name, you have got $mark ... | true |
29a45bee78b2ca23292e554f3d96a206dfce9e1d | debaonline4u/Python_Programming | /string_functions_in_python/string_function_center_ljust_rjust.py | 453 | 4.375 | 4 | # Python code to demonstrate working of
# center(), ljust() and rjust()
str = "geeksforgeeks"
# Printing the string after centering with '-'
print ("The string after centering with '-' is : ",end="")
print ( str.center(20,'-'))
# Printing the string after ljust()
print ("The string after ljust is : ",end="")
prin... | true |
607890591a6745e04229ad49080a34af90918738 | zhangda7/leetcode | /solution/_74_search_a_2D_matrix.py | 1,229 | 4.125 | 4 | # -*- coding:utf-8 -*-
'''
Created on 2015/7/30
@author: dazhang
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:
Integers in each row are sorted from left to right.
The first integer of each row is greater than the last integer of the previous row.... | true |
5c4f11e238a0dd47fddeff007707a00b389ac392 | pythonwithalex/Fall2014 | /week2/mutability.py | 836 | 4.46875 | 4 | # Programming With Python Week 2
# Mutability vs Immutability
# If a data type is mutable, parts of it can be changed and it is still the same 'object'.
# If a data type is immutable, then you can't change any part. You can only create an object by the same name and give it different values.
# Lists are mutable
#... | true |
0dae5b397f93b263bfecc3682edf263ac1a009a0 | go-bears/coding-challenges | /sum_3_to_0.py | 2,181 | 4.40625 | 4 | """
Write a function to determine if any 3 integers in an array sum to 0.
If so, return True if, else False
>>> is_sum_three_to_zero([1,-1,3,5,2,-2])
True
>>> is_sum_three_to_zero([1,1,1,1,1])
False
>>> is_sum_three_to_zero([1,-1])
False
>>> is_sum_three_to_zero([1,-1, 0])
True
"""
def is_sum_three_to_zero(lst)... | true |
a1ad614d6e4a92c1457b89125d1f74d9bfbb14e8 | a1ip/checkio-17 | /feed-pigeons.py | 931 | 4.125 | 4 |
def checkio(food):
minute = 0
fed_pigeons = 0
pigeons = 0
while True:
minute += 1
old_pigeons = pigeons
pigeons += minute
if food < pigeons:
# to feed sombody from newly arrived pegions
# if remains_food < 0, means that only 3 distinct pigeons ... | true |
caa1f296c7a4868110314debe4ac821ea99a20a6 | gcgc100/mypythonlib | /gClifford/setTools.py | 616 | 4.25 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
def merge_set_from_pairs(pairs):
"""Merge to a serious of set from a list of pairs
e.g. [1,2] [2,3] [5,6] [9,8] [1,3] -> [1,2,3] [5,6] [8,9]
:pairs: a list of pairs, every pair has two value
"""
setResult = []
for p in pairs:
assert len(... | true |
604febde80e37c3d2b2f8e700973b850522a24bb | KellyJason/Python-Tkinter-example. | /Tkinter_Walkthrough_3.py | 1,394 | 4.28125 | 4 | import os
import tkinter as tk
#begining of the window
root= tk.Tk()
#this creates an area for the labes and button to go in
canvas1 = tk.Canvas(root, width = 350, height = 400, bg = 'lightsteelblue2', relief = 'raised')
canvas1.pack()
# this is the label
label1 = tk.Label(root, text='Hello Kelly Girls,''... | true |
012d9c61edc947b5903c70e1871587391ebede71 | diallog/GCPpy | /01_listExercise.py | 1,074 | 4.15625 | 4 | #!/usr/bin/env python3
# obtain name and age data for multiple people until entering 'stop'
# then report who is the oldest person
# use lists for this exercise
import os
os.system('clear')
# initialize variables
nameList = []
ageList = []
newName = None
newAge = 0
maxAge = 0
maxIndex = 0
# get input
newName = inpu... | true |
12c512b16f6ff3f3b68a3766d513617b758518a1 | diallog/GCPpy | /listExercise.py | 438 | 4.15625 | 4 | #!/usr/bin/env python3
# input name and age for multiple people until entering 'stop'
# then report who is the oldest person
# use lists for this exercise
# initialize variables
newName = None
listIndex = 0
maxAge = 0
names = []
ages = []
# get input
newName = input ("What is the person's name?")
try:
if type(... | true |
04b758aea347fa68ae3d73565b85f2a400e76057 | shirish-babbur/Python | /ex6.py | 779 | 4.5625 | 5 | #Different ways to format or concatination of strings.
types_of_people = 10
x = f"There are {types_of_people} types of people."
#F'string example for storing in varibles
binary = "binary"
do_not = "don't"
y = f"Those who know {binary} and those who {do_not}."
#1 #2
p... | true |
e77eafb6540aa0eb93f82ef966c063db852d67b5 | rahlk/algorithms-in-py | /mergesort.py | 2,557 | 4.21875 | 4 | import numpy as np
from pdb import set_trace
def _merge(one, two):
"""
Merge two arrays
Parameters
----------
one : <numpy.ndarray>
A sorted array
two : <numpy.ndarray>
A sorted array
Returns
-------
<numpy.ndarray>
Merged array
Notes
-----
1.... | true |
b6f99862030a2f99685e1570afaa1f020a38f11a | mrutyunjay23/Python | /topics/Closure.py | 638 | 4.4375 | 4 | '''
Closure
'''
def outerFunction(num1):
def innerFunction(num2):
return num2 ** num1
return innerFunction
x2 = outerFunction(2) #num1 will be 2
print(x2(10)) #num2 will be 10 and num1 = 2
print(x2(20)) #num2 will be 20 and num1 = 2
'''
the value num1 is 2 is carreid in both the statement
Hence ... | true |
45887c00e398049a52c41a583970207ed0a3a065 | Frankiee/leetcode | /array/73_set_matrix_zeroes.py | 2,674 | 4.1875 | 4 | # https://leetcode.com/problems/set-matrix-zeroes/
# 73. Set Matrix Zeroes
# History:
# Facebook
# 1.
# Mar 8, 2020
# 2.
# Apr 22, 2020
# Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-place.
#
# Example 1:
#
# Input:
# [
# [1,1,1],
# [1,0,1],
# [1,1,1]
# ]
# Output:
# [
... | true |
31096b265c03c796fbac2e9adb05edf6cf74df49 | Frankiee/leetcode | /archived/array/1138_alphabet_board_path.py | 2,860 | 4.1875 | 4 | # [Archived]
# https://leetcode.com/problems/alphabet-board-path/
# 1138. Alphabet Board Path
# On an alphabet board, we start at position (0, 0), corresponding to
# character board[0][0].
#
# Here, board = ["abcde", "fghij", "klmno", "pqrst", "uvwxy", "z"], as shown
# in the diagram below.
#
#
# We may make the follo... | true |
681a2024de2d9d5091578a2299eae897946f02c7 | Frankiee/leetcode | /archived/string/383_ransom_note.py | 1,189 | 4.125 | 4 | # [Archived]
# https://leetcode.com/problems/ransom-note/
# 383. Ransom Note
# Given an arbitrary ransom note string and another string containing
# letters from all the magazines, write a function that will return true if
# the ransom note can be constructed from the magazines ; otherwise, it will
# return false.
#
#... | true |
c4a8e21d1e7a821860d0626fcd95a1b7db7f9293 | Frankiee/leetcode | /graph_tree_bfs/1129_shortest_path_with_alternating_colors.py | 2,881 | 4.25 | 4 | # https://leetcode.com/problems/shortest-path-with-alternating-colors/
# 1129. Shortest Path with Alternating Colors
# Consider a directed graph, with nodes labelled 0, 1, ..., n-1. In this
# graph, each edge is either red or blue, and there could be self-edges or
# parallel edges.
#
# Each [i, j] in red_edges denote... | true |
957535ca6554972ba06a5a925b12a787dcb177b7 | Frankiee/leetcode | /graph_tree_dfs/backtracking/282_expression_add_operators.py | 2,147 | 4.125 | 4 | # [Backtracking, Classic]
# https://leetcode.com/problems/expression-add-operators/
# 282. Expression Add Operators
# History:
# Facebook
# 1.
# Jan 23, 2020
# 2.
# Apr 1, 2020
# 3.
# May 10, 2020
# Given a string that contains only digits 0-9 and a target value, return all possibilities to
# add binary operators (no... | true |
838ad53e6d388f2b042a685bea4895cf0891b5dc | Frankiee/leetcode | /multithreading/1114_print_in_order.py | 2,339 | 4.25 | 4 | # https://leetcode.com/problems/print-in-order/
# 1114. Print in Order
# History:
# Apple
# 1.
# Aug 10, 2019
# 2.
# Mar 19, 2020
# Suppose we have a class:
#
# public class Foo {
# public void first() { print("first"); }
# public void second() { print("second"); }
# public void third() { print("third"); }
# }
... | true |
d90a04337c5ee794418cfa1f6e5fb129bbe039b1 | Frankiee/leetcode | /trie/208_implement_trie_prefix_tree.py | 2,064 | 4.15625 | 4 | # https://leetcode.com/problems/implement-trie-prefix-tree/
# 208. Implement Trie (Prefix Tree)
# History:
# Facebook
# 1.
# May 7, 2020
# Implement a trie with insert, search, and startsWith methods.
#
# Example:
#
# Trie trie = new Trie();
#
# trie.insert("apple");
# trie.search("apple"); // returns true
# trie.s... | true |
fb4e34c477459204d46e5ed59b22406cf24eb148 | Frankiee/leetcode | /graph_tree_bfs/199_binary_tree_right_side_view.py | 1,930 | 4.21875 | 4 | # https://leetcode.com/problems/binary-tree-right-side-view/
# 199. Binary Tree Right Side View
# History:
# Facebook
# 1.
# Mar 15, 2020
# 2.
# Apr 22, 2020
# Given a binary tree, imagine yourself standing on the right side of it, return the values of
# the nodes you can see ordered from top to bottom.
#
# Example:
... | true |
992fe8cd658ec4c5725bc4f8a0239afa7516bb16 | CarYanG/leetcode_python | /question_6.py | 1,601 | 4.34375 | 4 | #-*-coding:utf-8-*-
__author__ = 'carl'
'''
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this:
(you may want to display this pattern in a fixed font for better legibility)
P A H N
A P L S I I G
Y I R
And then read line by line: "PAHNAPLSIIGYIR"
Write the code that... | true |
341ec125e3f71f1f11d3f26bbeb561f028afb555 | vardhanvenkata/Text_to_speech | /Text_to_speech_with_UserInput.py | 486 | 4.125 | 4 | #import gtts module for text to speech conversion
import gtts
#import os to start the audio file
import os
#Taking input from user to convert it into speech
myText = input("Enter text to convert into Speech")
#language we want to use--In this case en--stands for english
language ='en'
output = gtts.gTTS(t... | true |
9827dfe610c7a2bfecd5a7cd3be2598136bdbeb1 | stevemman/FC308-Labs | /Lab1/A3.py | 312 | 4.21875 | 4 | # Store information about our trapezoid.
base1 = 8
base2 = 7
height = 12
# Calculate the area for our trapezoid.
# Be careful on the order of operations, use brackets when needed.
area = ((base1 + base2) / 2) * height
# Print the area of the trapezoid to the user.
print("The area of the trapezoid is:", area)
| true |
dc08f31c3dfec4fb04bd855ba9e89faca3fd7490 | stevemman/FC308-Labs | /Lab6/Task4.py | 1,439 | 4.21875 | 4 | # One function per calculator operation.
def add(num1, num2):
return num1 + num2
def subtract(num1, num2):
return num1 - num2
def multiply(num1, num2):
return num1 * num2
def divide(num1, num2):
return num1 / num2
print("Welcome to the advanced calculator 9001")
# Infinite loop that will stop o... | true |
067d5d9a5069719dcfef2ac2cd3e6261803a62ae | stevemman/FC308-Labs | /Lab2/Task1.py | 308 | 4.4375 | 4 | # Ask the user for height and width of the rectangle in cm.
height = int(input("Enter the height: "))
width = int(input("Enter the width: "))
# Calculate and print the area of the rectangle.
print("The area of the rectangle with height", height, "cm and width", width, "cm is", height * width, "square cm")
| true |
d5b98d6df8f3bd89486c9442933019bb84452b44 | stevemman/FC308-Labs | /Lab3/A1.py | 344 | 4.25 | 4 | # Ask the user to enter their age.
age = int(input("Please enter your age :"))
# Depending on the age group display a different ticket price.
if age > 0 and age < 18:
print("The ticket costs : 1.50£")
elif age >= 18 and age < 65:
print("The ticket costs : 2.20£")
elif age >= 65 and age < 100:
print("The ti... | true |
b562066ca6fefddfeef8728b7ec9834a8f3e52b1 | torz/awstest | /interview.py | 627 | 4.1875 | 4 |
def isValid(s):
parenthesis = 0
for i in s:
if i == '(':
parenthesis += 1
if i == ')':
parenthesis -= 1
if parenthesis < 0:
return False
if parenthesis == 0:
return True
else:
return False
if __name__ == '__main__':
pri... | true |
69f64f9ad1145969985f3d371ef68d14ccfb69c6 | KristinaKeenan/PythonWork | /Lab9/Lab9.py | 2,367 | 4.15625 | 4 | #Kristina Keenan
#4/8/15
#The purpose of this program is to take an inputed phrase and check to see if it spelled correctly.
def wordIndex():
'''This function reads a file and creates a list of words from it.'''
wordIndex1 = open("words1.txt", "r")
#wordIndex2 = open("words2.txt","r")
words1 = word... | true |
519bc18cdbb83f4466852f1ec5bdf6e9d2eecacc | KristinaKeenan/PythonWork | /2_4_15.py | 916 | 4.15625 | 4 | #Kristina Keenan
#2/5/15
#The purpose of this program is to drawn increasingly lighter and larger cocentric cirlces
#import and set up turtle
import turtle
wn = turtle.Screen()
square = turtle.Turtle()
#write a statement to determine how many squares
squareNumber = int(input("How many squares are you drawing?"))
#i... | true |
0b40a9765c9ed4c480c868384d1195cbe32d3578 | wiktorfilipiuk/pythonML | /myImplementation/myFunctions/distance.py | 709 | 4.40625 | 4 | def distance(x_start, x_end, n=1):
""" x_start, x_end - 2 vectors between which distance is to be measured
n - order of the measured distance according to Minkowski distance's definition
"""
if len(x_start) != len(x_end):
print("[ERROR] - Inconsistent dimensions of input vectors!")
result = -1
elif n < 1:
p... | true |
7032638ce55e5ab5c99abe7f74e4a2960a5c6303 | Researcher-Retorta/Python_Data_Science | /Week_01/Objects_and_map().py | 774 | 4.34375 | 4 | # An example of a class in python
class Person:
department = 'School of Information' #a class variable
def set_name(self, new_name): #a method
self.name = new_name
def set_location(self, new_location):
self.location = new_location
person = Person()
person.set_name('Christopher Br... | true |
4e239504c88dfcefbb37eeca6dfeb6987666a6dd | shubee17/HackerEarth | /Basic_IO/Riya_in_AngleHack.py | 714 | 4.21875 | 4 | """
Riya is getting bored in angelhack then Simran came with a game in which there is given a number N . If the number is divisible by 3 then riya has to print Angel and if number is divisible by 5 then she has to print Hack and if divisible by both then she has to print AngelHack! .If N does not satisfy any condition ... | true |
6c014ebe86e6aa10129f7081674ed8435a420b11 | kinsanpy/LearnPythonTheHardWay | /ex3.py | 786 | 4.5 | 4 | print "I will now count my chickens:"#print a line
print "Hens", 25 + 30 / 6# print a world and do the math
print "Roosters", 100 - 25 * 3 % 4#the same as above
print "Now I will count the eggs:"# print a line
print 3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6# print the result of the math
print "Is it true that 3 + 2 < 5 - 7... | true |
2d4f702901ba51248dd16b0edae00d106087106d | RyCornel/C.S.-1.0-Lists---Loops-Tutorial- | /lists_loops.py | 753 | 4.15625 | 4 | #Q1
songs =["ROCKSTAR", "Do It", "For the Night"]
print(songs[1])
#Q2
print(songs[0:3])
print(songs[1:3])
#Q3
songs[0] = "Dynamite"
print(songs)
songs[2] = "Everything I Wanted"
print(songs)
#Q4
songs.append("Roman Holiday")
songs.extend(["Do What I Want"])
songs.insert(3, "3:15")
print(songs)
songs.pop(0)
de... | true |
aaee654bec20080a90564db40433e0bfed270110 | Torrontogosh/MITx-6.00.1x | /Unit 01/Finger Exercise 01.py | 589 | 4.15625 | 4 | # This exercise was written with the assumption that none of the variables defined at the top would be over 1000. It simply tries to place the lowest odd number into the variable "lowest_number", and either prints that number out or prints a message that there are no odd numbers.
x = 10
y = 30
z = 14
lowest_number =... | true |
ec6538eaa41e598c2f801f366d95668b2fa698f7 | deepdhar/Python-Programs | /Basic Programs/count_vowels_consonants.py | 288 | 4.125 | 4 | #program to count vowels and consonants of a string
str1 = input()
vowels = "aeiou"
count1 = 0
count2 = 0
for ch in str1.lower():
if ch>='a' and ch<='z':
if ch in vowels:
count1 += 1
else:
count2 += 1
else:
continue
print("Vowels: {}\nConsonants: {}".format(count1,count2)) | true |
0e522a99d76e46d378727712343dcfc0427de090 | comptoolsres/Class_Files | /Examples/square.py | 295 | 4.3125 | 4 | #!/usr/bin/env python
# square.py: Demo of argparse
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("square", help="display a square of a given number",
type=float)
args = parser.parse_args()
print(f"The square of {args.square} is {args.square**2}")
| true |
f8b165301c9931121105e87cc13f486c6d1fcd15 | EricOHansen5/Algorithm-Challenges | /find_max_len of valid parenthesis.py | 1,586 | 4.21875 | 4 | #https://practice.geeksforgeeks.org/problems/valid-substring/0
#------------------------
#Given a string S consisting only of opening and closing parenthesis 'ie '(' and ')', find out the length of the longest valid substring.
#NOTE: Length of smallest the valid substring ( ) is 2.
#Input
#The first line of input ... | true |
607c1a638a2e5898b0a5f9de93c75e1599e46e86 | kevinelong/PM_2015_SUMMER | /StudentWork/RachelKlein/list_to_string.py | 740 | 4.4375 | 4 | one_string = ['Jay']
two_strings = ['Stephen', 'Dar']
three_strings = ['Reina', 'Ollie', 'Rachel']
# This prints a list of items as a string with the Oxford comma.
# If I could do this method again I would make it a lot simpler so the same code would handle any length of list.
def list_to_string(list):
length = l... | true |
11af401446614bff9bd92c1eff3e63cfac1b1e34 | kevinelong/PM_2015_SUMMER | /StudentWork/JayMattingly/PMSchoolWork/Code_challenges/python_files/For_while_practice.py | 1,685 | 4.28125 | 4 | #Write a program that will bring out the time every second for 10 seconds.(must use a loop of some kind)
# import time #imports time method
#
# count = 0 #set the count to start to 0
#
# while True: #begins looking ... | true |
8ce79891fdf8b62f72757f585619a32619b6b5e9 | lytvyn139/udemy-complete-python3-bootcamp | /26-nested-statements.py | 1,459 | 4.375 | 4 | x = 25
def printer():
x = 50
return x
print(x) #25
print(printer()) #50
"""
LEGB Rule:
L: Local — Names assigned in any way within a function (def or lambda), and not declared global in that function.
E: Enclosing function locals — Names in the local scope of any and all enclosing functions (def or lambda)... | true |
e7cbf1db6c2087acf014cfec0352756fdc566ffe | pr0videncespr0xy/Providence | /Guessing Game.py | 1,002 | 4.3125 | 4 | #Import random module
import random
#Print out greeting
print("Welcome to the guessing game!!!")
#set number of guesses and define a variable for the user winning
number_of_guess = 3
user_won = False
#Set answer
correct_answer = random.randint(1, 10)
#set number of guesses and set assign variable as in... | true |
8bb1001861c4764b5d72abf72af6e3596d920b2b | milosmatic1513/Python-Projects | /py_rot13_ergiasia3/python_rot13.py | 1,006 | 4.15625 | 4 | import rot13_add
final="";
while True:
ans=raw_input("Would you like to read from a file or directly input the text? (file/text)")
if (ans=="file"):
while True:
try:
input_file=raw_input("Input file to read from :(type 'exit' to exit) ")
if (input_file=="exit"):
break
inp=open(input_file,"r")
... | true |
d68e8f5473bb57678fde2bd302351690f17d1992 | bethbarnes/hashmap-implementation | /linkedlist.py | 1,812 | 4.15625 | 4 | #!/usr/bin/env python
#---------SOLUTION----------#
#define Node class
class Node:
def __init__(self, key=None, val=None):
self.next_node = None
self.key = key
self.val = val
#define Linked List class
class Linked_List:
def __init__(self):
self.head = None
#add new node to head
def add_LL_node... | true |
34b6cb57b77cae82e4beff1b8f0e968a3136abac | vijaymaddukuri/python_repo | /training/DataStructures-Algorithm/Tree/13root_to_leaf_sum_equal.py | 1,380 | 4.34375 | 4 | """
For example, in the above tree root to leaf paths exist with following sums.
21 –> 10 – 8 – 3
23 –> 10 – 8 – 5
14 –> 10 – 2 – 2
So the returned value should be true only for numbers 21, 23 and 14.
For any other number, returned value should be false.
"""
class Node:
# Constructor to create a new node
de... | true |
7e4826bf346984ffe46cf8fb648c11c848be6c53 | vijaymaddukuri/python_repo | /machine_learning/numpy_modules/index_100_element.py | 336 | 4.1875 | 4 | """
Index of the 100th Element
Consider an (11,12) shape array. What is the index (x,y) of the 100th element? Note: For counting the elements, go row-wise.
For example, in the array:
[[1, 5, 9],
[3, 0, 2]]
the 5th element would be '0'.
"""
import numpy as np
array1 = np.array(range(1, 11*12+1))
print(np.unravel_ind... | true |
c6001e535885859595c81fc65debcd6e0b2c0e8d | chasevanblair/mod10 | /class_definitions/customer.py | 1,989 | 4.25 | 4 | class Customer:
"""
Program: customer.py
Author: Chase Van Blair
Last date modified: 7/5/20
The purpose of this program is to get used to making classes
and overriding built in functions
"""
def __init__(self, id, lname, fname, phone, address):
"""
constructor for ... | true |
36b78478c176c74b8e2bd686ce633668a203601e | deep56parmar/Python-Practicals | /practical9.py | 407 | 4.125 | 4 | class Vol():
"""Find volume of cube and cylinder using method overloading."""
def __init__(self):
print("")
def volume(self,data1 = None, data2 = None):
if data1 and not data2:
print("Volume of cube is ", data1**3)
elif data1 and data2:
print("volume of cylind... | true |
058eaad4b5418a027282d45071f9a23b3655e9b7 | ThomasBaumeister/oreilly-intermediate-python | /warmup/vowels.py | 236 | 4.25 | 4 | #!/usr/bin/python3
import scrabble
vowels="aeiou"
def has_all_vowels(word):
for vowel in vowels:
if vowel not in word:
return False
return True
for word in scrabble.wordlist:
if has_all_vowels(word):
print (word)
| true |
e5e5ba6956c0133d5b5632fe7df04e3d9cae17b6 | rebht78/Python-Exercises | /exercise29.py | 527 | 4.34375 | 4 | """
We are used to list now, let's introduce some more functions to list.
So moving further,
String is also a kind of list. Because String is a collection of
characters.
If string in python is a collection of characters (list), then
we can use all the techniques of list with strings too.
Let's see an example of al... | true |
1ecc10b55b6c37a8018993ec7836cc791fcec003 | rebht78/Python-Exercises | /exercise27.py | 551 | 4.75 | 5 | """
We can access more than one elements using index range.
Suppose a list name is countries.
we can access elements like countries[startindex:endindex]
startindex: starting of index
endindex: till endindex-1
Let's see an example
"""
countries = ['USA','Canada','India','Russia','United Kingdom'];
print(countries[1... | true |
9c8401be726083d2d245e03e6ec55b81d5b708a9 | rebht78/Python-Exercises | /exercise24.py | 594 | 4.59375 | 5 | """
We have learn a lot about python.
Now let's move forward and learn Sequences or Lists.
Lists are collection of values.
Why we need a list in first place?
Let's say you need to store name of all the countries in the world
to store their GDP numbers.
You can go on and create 190+ variables for storing country nam... | true |
9c48c238300cf599444b45a59c53749dc8dcfdbd | rebht78/Python-Exercises | /exercise17.py | 520 | 4.21875 | 4 | """
Let's do two more if...else programs to get used to new syntax
of Python.
Problem Statement:
Write a program that display max of two numbers
Sample Input/Output:
3
5
5 is greater than 3
Let's write the program using if...else block
"""
number1 = 3
number2 = 5
if number1 > number2:
# three statements in if...i... | true |
a745d83b5d9e58ef8b252d9de6485fba11718289 | cmanage1/codewars | /GetMiddleChar.py | 360 | 4.1875 | 4 | #GetMiddleCharacter
#You are going to be given a word. Your job is to return the middle character
#of the word. If the word's length is odd, return the middle character.
#If the word's length is even, return the middle 2 characters.
def get_middle(s):
if len(s) % 2 == 0:
return s[len(s)/2-1] + s[len(s)/2]... | true |
bc5077b9b508b820a70a3dd1f7d1f3796609a297 | Linda-Kirk/cp1404practicals | /prac_09/sort_files_2.py | 1,483 | 4.125 | 4 | import shutil
import os
def main():
"""Create folders from user input and sort files on extension according to user preferences"""
print("Starting directory is: {}".format(os.getcwd()))
# Change to desired directory
os.chdir('FilesToSort')
print("Changed directory is: {}".format(os.getcwd()))
... | true |
32015b23ce5e30803fd8f2d086122e87c23bc0ed | Linda-Kirk/cp1404practicals | /prac_02/ascii_table.py | 715 | 4.5625 | 5 | """
This program will generate an ASCII code when a character is inputted by a user
or generate a character when an ASCII code inputted by a user
"""
LOWER = 33
UPPER = 127
character = input("Enter a character: ")
print("The ASCII code for {} is {}".format(character, ord(character)))
ascii_code = int(input("Enter a... | true |
f0a4498e4c92f8789a813c62c50732adf39b7fc1 | chin33029/python-tutorial | /notes/day_05/dictionary.py | 1,601 | 4.15625 | 4 | # variables
# var = 1
# var = 'string'
# var = 1.0
# var = [0,1,2,3]
# dictionary
# var = {
# "name": "Dean",
# "phone": "123-456-7890"
# }
# dictionary consists of key/value pairs
# {
# key1: value1,
# key2: value2
# }
# person = {
# 'firstName': 'Dean',
# 'lastName': 'Chin',
# 'phone': '123... | true |
3d82545a9663de8e2b79d2e5111529cc4ded7605 | chin33029/python-tutorial | /assignments/solutions/assignment_02.py | 1,936 | 4.3125 | 4 | """ Assignment 02 - Bank Example """
def deposit(amount, balance):
""" Deposit money to account """
return int(balance) + int(amount)
def withdraw(amount, balance):
""" Withdraw money from account """
if int(amount) > int(balance):
print(f'Unable to withdraw {amount}, you only have {balance}... | true |
2fb88d34c58a9d27256856585c7230371f23aeda | ppradnya18/first-Basic | /caleder_module.py | 301 | 4.15625 | 4 | """12. Write a Python program to print the calendar of a given month and year."""
import calendar
import inspect
print(calendar.Calendar)
print(inspect.getfile(calendar))
print(dir(calendar))
y = int(input("Input the year : "))
m = int(input("Input the month : "))
print(calendar.month(y, m))
| true |
11e2a969f22e542a611090dd3271d386ba17476b | welydharmaputra/ITP-lab | /New triangle.py | 2,482 | 4.1875 | 4 | def main():
for x in range(1,6): # it will make the stars go down
for z in range(1,int(x)+1,1): # it will make the star increase one by one
print("*",end="") #it will print the stars and make the stars to make a line that from left to the right
print() # it make the stars can be show... | true |
137dc3aa161daf4a4e6d0f4e666cd232c4dd0225 | sureshyhap/Python-Crash-Course | /Chapter 7/6/three_exits.py | 509 | 4.1875 | 4 | topping = ""
while topping != "quit":
topping = input("Enter a topping: ")
if topping != "quit":
print("I will add " + topping + " to the pizza")
active = True
while active:
topping = input("Enter a topping: ")
if topping == "quit":
active = False
else:
print("I will add " +... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.