blob_id string | repo_name string | path string | length_bytes int64 | score float64 | int_score int64 | text string | is_english bool |
|---|---|---|---|---|---|---|---|
483a6e8f975974e3b754109e4b72b18c0783e1b6 | Makhanya/PythonMasterClass | /TuplesSets/tuple.py | 524 | 4.21875 | 4 | # Tuples are commonly used for Unchanging data:
months = ("January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December")
# Tuple can be used as keys in dictionaries
locations = {
(35.68995, 39.6917): "Tokyo Office",
(40.7128, 74.0060): "New Y... | true |
27d974269a5d178efe810beddf8efc2a7db0f4c3 | Makhanya/PythonMasterClass | /TuplesSets/Sets.py | 1,399 | 4.625 | 5 | # Sets
# Sets are like formal mathematical sets
# Sets do not have duplicate values
# Elements in sets aren't ordered
# You cannot access items in a set by index
# Sets can be useful if you need to keep track of a collection of
# elements, but don;t care about ordering, Keys or... | true |
27ab1bab32d6bdc3f021bf7ca29e7d2821c32dac | fgokdata/exercises-python | /coursera/functions.py | 515 | 4.125 | 4 | def printAll(*args): # All the arguments are 'packed' into args which can be treated like a tuple
print("No of arguments:", len(args))
for argument in args:
print(argument)
#printAll with 3 arguments
printAll('Horsefeather','Adonis','Bone')
#printAll with 4 arguments
printAll('Sidecar','Long Island','M... | true |
983437a9e05194097f02d0f154dc8e9a5419d7d6 | Puqiyuan/Example-of-Programming-Python-Book | /chapter1/person_alternative.py | 1,357 | 4.34375 | 4 | """
a complete instance example of OOP in python.
test result:
pqy@sda1:~/.../chapter1$ python person_start.py
Bob Smith 40000
Smith
44000.0
"""
class Person:
"""
a general person: data + logic
"""
def __init__(self, name, age, pay = 0, job = None):
self.name = name
self.age = age
... | true |
da1d96284276b485582823b463700d9956e01725 | KahlilMonteiro-lpsr/class-samples | /6-3CaesarsCipher/applyCipher.py | 1,349 | 4.34375 | 4 | # applyCipher.py
# A program to encrypt/decrypt user text
# using Caesars Cipher
#
# Author: rc.monteiro.kahlil [at] leadps.org
import string
# makes a mapping of alphabet to decoded alphabet
# arguments: key
# returns: dictionary of mapped letters
def createDictionary(key):
alphabet = list(string.ascii_lowercase)
a... | true |
90b8498a0612e66df9743ed07a3521a145c8d918 | bhayru01/Python-Exercises | /addFloatNumbers.py | 1,723 | 4.5 | 4 | ####### File Exercise from the book "Python For Everyone" by Horstmann #######
"""
Write a program that asks the user to input a set of floating-point values.
When the user enters a value that is not a number,
give the user a second chance to enter the value.
After two chances, quit reading input.
Add all correct... | true |
f31b5a47fd89394ef9725443e3aa463b79bc9c50 | bhayru01/Python-Exercises | /NumberOfCharsWordsLines.py | 1,537 | 4.3125 | 4 | ####### File Exercise from the book "Python For Everyone" by Horstmann #######
"""
p7.5
Write a program that asks the user for a file name
and prints the number of:
characters, words, and lines in that file.
"""
file = open("input.txt", "w")
file.write("Mary had a little lamb\nWhose fleece was whit... | true |
b5060a2f70653672895b2225e76c2bf1ddc2e573 | cervthecoder/scratch_code | /begginning_cerv/user input.py | 243 | 4.28125 | 4 |
name = input("Enter your name: ") #user put here some infromation which is stored inside a variable
age = input ("enter your age: ")
print("Hello " +name+ "! Your age is "+age+".") #prints the variables plus some other information (string)
| true |
15e424f10556b081b77b9033d89abdc0051f60af | cervthecoder/scratch_code | /begginning_cerv/if statement.py | 307 | 4.21875 | 4 |
is_male = False #make a true/false value
is_tall = False
if is_male and is_tall:
print("You're a male and tall")
elif is_male and not(is_tall):
print("You're a short male")
elif not (is_male) and is_tall:
print("You're a tall female")
else:
print("You're a female and not tall")
| true |
3a11b81f210e012e7fce39a2d40387e8d2dd7dc3 | CODavies/Python_Dietel | /Chapter2/Multiples_Of_A_Number.py | 274 | 4.15625 | 4 | first_Number = int(input('Enter first number: '))
second_Number = int(input('Enter second number: '))
if second_Number % first_Number == 0:
print(first_Number, " is a multiple of ", second_Number)
if second_Number % first_Number != 0:
print("The are not multiples") | true |
cfdec71e99f0b3a80db0681d590e988193bbc783 | HarshRangwala/Python | /python practice programs/GITpractice31.py | 1,437 | 4.65625 | 5 | # -*- coding: utf-8 -*-
"""
Created on Fri Jun 15 14:36:13 2018
@author: Harsh
"""
'''
Define a function which can generate and print a list where the values are square of numbers between 1 and 20 (both included).
Hints:
Use ** operator to get power of a number.
Use range() for loops.
Use list.append() to add value... | true |
b519c13d65845d3b859878a27608f8bdd1eda9e2 | HarshRangwala/Python | /python prc/PRACTICAL1E.py | 1,102 | 4.1875 | 4 | # -*- coding: utf-8 -*-
"""
Created on Tue Jun 5 18:26:47 2018
@author: Harsh
"""
def Armstrong():
num=int(input("Please Input here::"))
# initialize sum
sum = 0
# find the sum of the cube of each digit
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** 3
... | true |
d573c3a0f4641b652c6a421630ae6273c2520683 | HarshRangwala/Python | /python practice programs/GITpractice16.py | 431 | 4.3125 | 4 | # -*- coding: utf-8 -*-
"""
Created on Sat Jun 9 23:30:39 2018
@author: Harsh
"""
'''
Use a list comprehension to square each odd number in a list. The list is input by a sequence of comma-separated numbers.
Suppose the following input is supplied to the program:
1,2,3,4,5,6,7,8,9
Then, the output should be:
1,3,5,7... | true |
27d7b880c1caf75afd0896a6d1ef6dac88659a5f | NareTorosyan/Python_Introduction_to_Data_Science | /src/first_month/Homeworks/task_1_2_1_lists.py | 440 | 4.34375 | 4 | #1 Write a Python program to get the largest number from a list.
x = [9,8,5,6,4,3,2,1]
x.sort()
print(x[-1])
#2 Write a Python program to get the frequency of the given element in a list to.
x =[1,2,3,4,5,6,7,8,9,9,9,9,9]
print(x.count(9))
#3 Write a Python program to remove the second element from a given list, if w... | true |
9dd831fc2689ea4f88ccabfcfc1625872360131e | tuantvk/python-cheatsheet | /src/python-example/string.py | 1,350 | 4.4375 | 4 | #!/usr/bin/python
str1 = 'Hello World!'
str2 = "I love Python"
print("str1[0]: ", str1[0])
print("str2[7:]: ", str2[7:])
# output:
# str1[0]: H
# str2[7:]: Python
# display multiline
str3 = """
Lorem Ipsum is simply dummy text of the printing
and typesetting industry. Lorem Ipsum has been the
industry's standa... | true |
ad987950a320d893b0b71089f95bdabe34176a87 | skywalker-young/LeetCode-creepy | /unique-path.py | 1,666 | 4.25 | 4 | """
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).
The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).
How many possible unique paths are there?
Not... | true |
18e0e1c83373e8fe96430fbb141330e06c143f1b | AishwaryaVelumani/Hacktober2020-1 | /rock paper scissors.py | 1,668 | 4.25 | 4 | import random
def result(your_score,comp_score):
if your_score>comp_score:
print("Congratulations! You won the match. Play again!")
elif your_score == comp_score:
print("The match is a tie! Play again!")
else :
print("Opps! You lost the match. Try again!")
def win(you... | true |
733464c49bc5ee51d3e2a4cc29f29f3a1db9171d | carlosalf9/InvestigacionPatrones | /patron adapter python/class Adapter.py | 544 | 4.1875 | 4 |
class Adapter: """ Adapts an object by replacing methods. Usage: motorCycle = MotorCycle() motorCycle = Adapter(motorCycle, wheels = motorCycle.TwoWheeler) """
def __init__(self, obj, **adapted_methods):
"""We set the adapted methods in the object's dict"""
self.obj = obj
self.__dict__.update(adapted_met... | true |
e029b1def2a907109eeaf9cb9434edec6eb40ddc | naistangz/codewars_challenges | /7kyu/shortestWord.py | 332 | 4.5625 | 5 | """
Instructions
- Simple, given a string of words, return the length of the shortest word(s).
- String will never be empty and you do not need to account for different data types.
"""
def find_short(s):
convert_to_list = list(s.split(" "))
shortest_word = min(len(word) for word in convert_to_list)
return s... | true |
fd90a725870c45b4a1c848893ad1dbf394ec5240 | naistangz/codewars_challenges | /7kyu/simpleConsecutivePairs.py | 1,639 | 4.28125 | 4 | """
Instructions
In this Kata your task will be to return the count of pairs that have consecutive numbers as follows:
pairs([1,2,5,8,-4,-3,7,6,5]) = 3
The pairs are selected as follows [(1,2),(5,8),(-4,-3),(7,6),5]
--the first pair is (1,2) and the numbers in the pair are consecutive; Count = 1
--the second pair is ... | true |
43a739e5ab9392456bde250693f404050234d895 | hamiltoz9192/CTI-110 | /P4HW2_Hamilton.py | 340 | 4.125 | 4 | #CTI-110
#P4HW2 - Running Total
#Zachary Hamilton
#July 6, 2018
#This program creates a running total ending when a negative number is entered.
total = 0
userNumber = float(input("Enter a number?:"))
while userNumber > -1:
total = total + userNumber
userNumber = float(input("Enter a number?:"))
pr... | true |
435b5497d7968cc076d860e436f4d9b7f109e336 | AShuayto/python_codewars | /data_reverse.py | 1,043 | 4.1875 | 4 | '''
A stream of data is received and needs to be reversed. Each segment is 8 bits long, meaning the order of these segments need to be reversed, for example:
11111111 00000000 00001111 10101010
byte1 byte2 byte3 byte4
should become:
10101010 00001111 00000000 11111111
byte4 byte3 byte2 ... | true |
cdaffc0412348680b67122b1a959ab448a4809eb | Md-Monirul-Islam/Python-code | /Advance-python/Constructor with Super Method-2.py | 531 | 4.21875 | 4 | #Constructor with Super Method or Call Parent Class Constructor in Child Class in Python
class Father:
def __init__(self):
self.money = 40000
print("Father class constructor.")
def show(self):
print("Father class instance method.")
class Son(Father):
def __init__(self):
super... | true |
2c91529b8b53c07adb1466be2b673aaf921efa6a | lrakai/python-newcomer-problems | /src/challenge_three.py | 893 | 4.5 | 4 | def list_uniqueness(the_list):
'''
Return a dictionary with two key-value pairs:
1. The key 'list_length' stores the lenght of the_list as its value.
2. The key 'unique_items' stores the number of unique items in the_list as its value.
Arguments
the_list: A list
Examples
l = [1, 2, 2... | true |
02e9d39c87c4456b5f5b3cfd8ed53b98db430328 | flik/python | /iterator.py | 576 | 4.53125 | 5 | #Return an iterator from a tuple, and print each value:
mytuple = ("apple", "banana", "cherry")
myit = iter(mytuple)
#myit = mytuple
print(next(myit)) # next() will not work without iter() conversion.
print(next(myit))
print(next(myit))
mystr = "banana"
for x in mystr:
print(x)
"""
#Strings are also iter... | true |
ade463aad6ee764d4627acc5927eb64d535135bc | ziminika/prak__5 | /task2/5/5.py | 2,790 | 4.1875 | 4 | from collections import defaultdict
import sys
# Description of class Graph:
# The Graph is a dictionary of dictionaries.
# The keys are nodes, and the values are dictionaries,
# whose keys are the vertices that are associated with
# a given node, and whose values are the weight of the edges.
# Non-oriented Gra... | true |
c8537ec4db97f54f6eab90aa26b3b0f03a79b3d2 | ziminika/prak__5 | /task2/4/4.py | 2,361 | 4.125 | 4 | from collections import defaultdict
from collections import deque
import sys
# Description of class Graph:
# The Graph is a dictionary of lists.
# The keys are nodes, and the values are lists,
# consisting of nodes that have a path fron a given node.
# Oriented Graph
class Graph:
# Сreating a Graph object
def _... | true |
e34199254a7fea1aea5f3e02310652c367f1897c | YaoJMa/CS362-HW3 | /Yao_Ma_HW3_Leap_Year.py | 483 | 4.28125 | 4 | #Asks user for a input for what year
year = int(input("Enter a year: "))
#Checks the conditions if the year is divisible by 400
if year%400==0:
print("It is a leap year")
#Checks the conditions if the year is divisible by 100 and 400
elif year%100==0 and year%400!=0:
print("It is not a leap year")
#C... | true |
26602c6aeda22ee4cd53bb346f9c96604200ef73 | vitthalpadwal/Python_Program | /hackerrank/preparation_kit/greedy_algorithms/max_min.py | 1,761 | 4.28125 | 4 | """
You will be given a list of integers, , and a single integer . You must create an array of length from elements of such that its unfairness is minimized. Call that array . Unfairness of an array is calculated as
Where:
- max denotes the largest integer in
- min denotes the smallest integer in
As an example, con... | true |
ab76daedef7fc55f293b31010b84f62472d2e028 | vitthalpadwal/Python_Program | /hackerrank/algorithm/strings/super_reduces_strings.py | 1,456 | 4.34375 | 4 | """
Steve has a string of lowercase characters in range ascii[‘a’..’z’]. He wants to reduce the string to its shortest length by doing a series of operations. In each operation he selects a pair of adjacent lowercase letters that match, and he deletes them. For instance, the string aab could be shortened to b in one op... | true |
c5606deae4b3f8ac7e867c48c2d00c71317d78ab | vitthalpadwal/Python_Program | /hackerrank/decorator_standardize_mobile_no.py | 1,332 | 4.65625 | 5 | """
Let's dive into decorators! You are given mobile numbers. Sort them in ascending order then print them in the standard format shown below:
+91 xxxxx xxxxx
The given mobile numbers may have , or written before the actual digit number. Alternatively, there may not be any prefix at all.
Input Format
The first... | true |
268afaf374055a83b932122edd77f75d2b8abb14 | vitthalpadwal/Python_Program | /hackerrank/algorithm/strings/strong_password.py | 2,906 | 4.375 | 4 | """
Louise joined a social networking site to stay in touch with her friends. The signup page required her to input a name and a password. However, the password must be strong. The website considers a password to be strong if it satisfies the following criteria:
Its length is at least .
It contains at least one digit.... | true |
082b98374cec16d6f9aee1670ae6c5a3fcbac0f5 | vitthalpadwal/Python_Program | /hackerrank/algorithm/strings/caesar_cipher.py | 2,003 | 4.59375 | 5 | """
Julius Caesar protected his confidential information by encrypting it using a cipher. Caesar's cipher shifts each letter by a number of letters. If the shift takes you past the end of the alphabet, just rotate back to the front of the alphabet. In the case of a rotation by 3, w, x, y and z would map to z, a, b and ... | true |
741eac7bd97af4a06ae3c38252654b88cb9c0e73 | VitaliiRevenko/PytonLessonsForBeginnerBeetRootAcademy | /lesson_10/task1.py | 701 | 4.21875 | 4 | '''
Task 1
A Person class
Make a class called Person. Make the __init__() method take firstname, lastname, and age as parameters
and add them as attributes. Make another method called talk() which makes prints a greeting from the person containing
, for example like this: “Hello, my name is Carl Johnson and I’m ... | true |
a450d7febe14eacf228fa011272cd6d9fe78983e | robbailiff/maths-problems | /gapful_numbers.py | 937 | 4.1875 | 4 | """
A gapful number is a number of at least 3 digits that is divisible by the number formed by the first and last digit of the original number.
For Example:
Input: 192
Output: true (192 is gapful because it is divisible 12)
Input: 583
Output: true (583 is gapful because it is divisible by 53)
Input: 210
Output: fals... | true |
18756becf16c3252294155a8b01c82acba7a8fd4 | charugarg93/LearningML | /04_List.py | 1,219 | 4.59375 | 5 |
books = ['kanetkar', 'ritchie', 'tanenbaum']
print(books[2])
# in python you can also have negative indices
# -1 denotes last element of the list, -2 denotes second last item of the list and so on
print("Experimenting with negative indices ::: "+ books[-3])
books.append("galvin")
print(books)
# extend method is us... | true |
6b181ec8bd9d686fa14459e0b89dcfb96743dd69 | arunk38/learn-to-code-in-python | /Python/pythonSpot/src/3_database_and_readfiles/1_read_write/read_file.py | 397 | 4.125 | 4 | import os.path
# define a filename.
filename = "read_file.py"
# open the file as f
# The function readlines() reads the file.
if not os.path.isfile(filename): # check for file existence
print("File does not exist: " + filename)
else:
with open(filename) as f:
content = f.read().splitlines()
# sho... | true |
62ab746c5779f2deb2c4dd5a813fa34795b09978 | jleyva82/Resources | /file_creation.py | 762 | 4.125 | 4 | '''
Author = Jesus Leyva
Last Update: 01/28/2019
Purpose: Sample of how to use python to create a new file
sample resources as described via stack skills python lessons
'''
newfile = open("newfile.txt", "w+") #newfile variable is like a class.
... | true |
8633f7141389e8fbfabff287cf97602ff3a65533 | BoHyeonPark/BI_test | /bioinformatics_1_4.py | 391 | 4.1875 | 4 | #!/usr/bin/python
num1 = raw_input("Enter a integer: ")
num2 = raw_input("Enter another: ")
try:
num1 = int(num1)
num2 = int(num2)
except:
print "Enter only number!"
else:
if num1 > num2:
print "%d is greater than %d" % (num1, num2)
elif num1 < num2:
print "%d is less than %d" % (... | true |
93886ea9807f467a784600cbf3be7d2e60522a11 | klprabu/myprojects | /Python/HackerRank/DesignerMat.py | 1,581 | 4.21875 | 4 | # Set the design as per the input
#Mr. Vincent works in a door mat manufacturing company. One day, he designed a new door mat with the following specifications:
#Mat size must be X. ( is an odd natural number, and is times .)
#The design should have 'WELCOME' written in the center.
#The design pattern should on... | true |
cb3f2a2ba89d10eeb06bc7bdb3a1e205ade8ddeb | kiennd13/NguyenDucKien-Fundamentals-C4E30 | /Session 5/function_7,8.py | 352 | 4.125 | 4 | def remove_dollar_sign(s):
return s.replace("$","")
m = str(input("Nhập chuỗi : "))
t=remove_dollar_sign(m)
print(t)
string_with_no_dollars = remove_dollar_sign("$80% percent of $life is to show $up")
if string_with_no_dollars == "80% percent of life is to show up":
print("Your function is correct")
else:
... | true |
825f18874a543fe5162d409085f17def0aed29e9 | kiennd13/NguyenDucKien-Fundamentals-C4E30 | /Session 5/function_5,6.py | 481 | 4.21875 | 4 | from turtle import *
def draw_star(x,y,length):
up()
setposition(x,y)
down()
for _ in range(5):
left(144)
forward(length)
mainloop()
length = int(input("Length = "))
x = int(input("Position 1: "))
y = int(input("Position 2: "))
draw_star(x,y,length)
speed(0.3)
color('blue')
for i in ... | true |
e2d0c4546380e8e7e6a2268b69893dc78732266e | rsdarji/CEGEP-sem-2-Algorithm | /examples.py | 2,490 | 4.28125 | 4 | # ======================================================================================================================
# Printing
# ======================================================================================================================
"""
Basic user output in Python is done with 'print'.
Although we... | true |
3f30f28b8f3a8db8e53cab846a248d4b8c8f11ff | jeffrlynn/Codecademy-Python | /removeVowels.py | 250 | 4.3125 | 4 | #Remove all vowels from a string
def anti_vowel(text):
phrase = ""
for letter in text:
for vowel in "aeiouAEIOU":
if letter == vowel:
letter = ""
else:
letter = letter
phrase = phrase + letter
return phrase
| true |
f37185b847d2d868082ab9db5cca9a318f0632bb | GeertenRijsdijk/Theorie | /main.py | 2,649 | 4.15625 | 4 | '''
main.py
Authors:
- Wisse Bemelman
- Michael de Jong
- Geerten Rijsdijk
This file implements the front end for the algorithms and visualisation.
usage:
python main.py <datafile> <amount of houses> <algorithm>
example:
python main.py ./data/wijk_2.csv 60 r
The algorithm choices are located in th... | true |
9c13585b3241bdd8f0d5b538afee7044567cfe32 | TanyaMozoleva/python_practice | /Lectures/Lec11/p15.py | 736 | 4.1875 | 4 | '''
Using and if ... elif statement complete the compare_nums2()
function which is passed two integers and returns a string. The function
compares the first number to the second number and returns one of the
following three strings (i.e., the string which is applicable):
"equal to" OR "less than" OR "greater than"
'''
... | true |
759f3b296db18e6557f46ffa8bd99d48a713c247 | TanyaMozoleva/python_practice | /Lectures/Lec12/p13.py | 1,040 | 4.15625 | 4 | '''
A perfect number is an integer that is equal to the sum of its divisors
(including 1, excluding the number itself), e.g., the sum of the divisors of
28 is 28 (1 + 2 + 4 + 7 + 14). Complete the check_perfection()
function which checks for perfection and prints either '#is a
perfect number' or '#is NOT a perfect numb... | true |
9f3dda1df5bfb23fbc90698d6db2e62c37d0c37c | TanyaMozoleva/python_practice | /Weeks/week2/w2t2.py | 506 | 4.625 | 5 | '''
Complete the programm that prompts the user to enter a floatibg point value and
an unteger value and calculates and displays the value obtained when the floating point
value is raised to the power of the integer value. The result will be rounded to the
nearist 3 decimal places.
'''
number = float(input('Enter a fl... | true |
713b95248bac2b24e652bd1437ccc055598783c5 | TanyaMozoleva/python_practice | /Lectures/Lec4/p24.py | 315 | 4.28125 | 4 | '''
Complete the following program so that it prints the name between two rows of stars. The output has three spaces on each side of the name
'''
name = 'Philomena Evangeline'
extras = 3
symbol = '*'
lots_of_symbols = symbol * 26
print(lots_of_symbols)
print(' ' * extras, name, ' ' * extras, sep = '')
print(lots_of_... | true |
06d0a2da145a8c679ffc0c12bf9730233f8ec553 | TanyaMozoleva/python_practice | /Weeks/week2/w2t5.py | 387 | 4.28125 | 4 | '''
Write a program that prompts the user to enter a word.
In then prints a new word where the first and last characters of the word
entered by the user are swapped.
'''
word = input('Enter a word: ')
first_character = word[0]
last_character = word[-1]
middle_slice = word[1:-1]
new_word = last_character + middle_slic... | true |
00bdd1f1d9b9f76752edd0f65ea483a6fa039089 | cvhs-ap-2018/python-practice-exam-Alvarezchris23 | /graphics.py | 813 | 4.53125 | 5 | """
1. Write the lines of code that would import
and create a turtle named 'Pong'.
"""
import turtle
Pong = turtle.Turtle('turtle')
Pong.pd()
"""
2. Draw a square with Pong of length 100
"""
import turtle
Pong = turtle.Turtle('turtle')
for i in range(4):
Pong.fd(100)
Pong.rt(90)
"""
3. W... | true |
e229e096226f4e2cca03bc1250f079d122406250 | ZR-Huang/AlgorithmsPractices | /Leetcode/Basic/Dynamic_Programming/53_Maximum_Subarray.py | 662 | 4.15625 | 4 | '''
Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.
Example:
Input: [-2,1,-3,4,-1,2,1,-5,4],
Output: 6
Explanation: [4,-1,2,1] has the largest sum = 6.
Follow up:
If you have figured out the O(n) solution, try coding another solu... | true |
460e74a392f8586e88a120885f7cfe6c1400c525 | ZR-Huang/AlgorithmsPractices | /Leetcode/Intermediate/Array_and_string/73_Set_Matrix_Zeroes.py | 2,957 | 4.3125 | 4 | '''
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:
[
[1,0,1],
[0,0,0],
[1,0,1]
]
Example 2:
Input:
[
[0,1,2,0],
[3,4,5,2],
[1,3,1,5]
]
Output:
[
[0,0,0,0],
[0,4,5,0],
[0,3,1,0]
]
Follow ... | true |
17e86d07b7f438a8365650253f65130b0eebde87 | ZR-Huang/AlgorithmsPractices | /Leetcode/Basic/Math/326_Power_of_Three.py | 1,530 | 4.46875 | 4 | '''
Given an integer, write a function to determine if it is a power of three.
Example 1:
Input: 27
Output: true
Example 2:
Input: 0
Output: false
Example 3:
Input: 9
Output: true
Example 4:
Input: 45
Output: false
Follow up:
Could you do it without using any loop / recursion?
'''
class Solution:
def isPowerO... | true |
4b53b20061ab23c8e8f84ef083f0980dd482675f | ZR-Huang/AlgorithmsPractices | /Leetcode/Intermediate/Backtracking/78_Subsets.py | 611 | 4.46875 | 4 | class Solution:
'''
Computing the subset of the array can be considered as the selection of
every element of the array. Thus, the DFS algorithm is used to
search all the possible combinations. This method also called
backtrack algorithm.
'''
def subsets(self, nums):
result = []
... | true |
83cc10463f51848197a05dadf1be6a16bc96de01 | dziarkachqa/example_pytest | /src/src.py | 734 | 4.125 | 4 | def join_list(some_list: list) -> str:
"""Function joins list elements and strings"""
if not isinstance(some_list, list):
return "I need list!"
return "".join([str(el) for el in some_list])
def split_list(some_list: list, sep=None) -> tuple:
"""Function for splitting list by separator"""
if... | true |
7d1ed39f4b34b009182e04e7a4b6f62b4329357a | JeffreyAsuncion/SQLite_Databases_with_Python | /db001.py | 593 | 4.21875 | 4 | import sqlite3
# conn = sqlite.connect(':memory:') # to create a database in memory that disappear after done
conn = sqlite3.connect('customer.db')
# before create table need a cursor
# Create a cursor
cursor = conn.cursor()
# if we recreate a table we get an error
# # Create a table
# cursor.execute("""CREATE TA... | true |
03de7319b70da0d4bbbabcd4df51886b767857f9 | geniousisme/CodingInterview | /leetCode/Python/281-zigzagIterator.py | 946 | 4.21875 | 4 | # Given two 1d vectors,
# implement an iterator to return their elements alternately.
# For example, given two 1d vectors:
# v1 = [1, 2]
# v2 = [3, 4, 5, 6]
# By calling next repeatedly until hasNext returns false,
# the order of elements returned by next should be: [1, 3, 2, 4, 5, 6].
# Follow up: What if you are gi... | true |
f6225982288731faa7c4d02b279789b75796ff39 | jdmorrone01/Triangle567 | /TestTriangle.py | 2,140 | 4.125 | 4 | # -*- coding: utf-8 -*-
"""
Updated Jan 21, 2018
The primary goal of this file is to demonstrate a simple unittest implementation
@author: jrr
@author: rk
"""
import unittest
from Triangle import classifyTriangle
# This code implements the unit test functionality
# https://docs.python.org/3/library/unittest.html ha... | true |
105907e46fd1d42a49ce22765393ef5a88b39102 | anshul-musing/basic_cs_algorithms | /test_heap.py | 935 | 4.21875 | 4 |
from src.heap import MaxHeap
def testHeap():
'''
Here we test algorithms for a max heap
The heap class takes a balanced binary tree as
an input and converts it into a max heap
We test
a) building a max heap
b) heapify operation
Each node of the max heap is an object of
the... | true |
cc3a38c69c3105c5b40b7d2f968013f695454f8a | anshul-musing/basic_cs_algorithms | /test_graph.py | 1,284 | 4.34375 | 4 |
from src.graph import Graph
def testGraph():
'''
Here we test algorithms for graphs
We test
a) breadth first search
b) depth first search
c) minimum spanning tree using Prim's algorithm
d) shortest distance using Dijkstra's algorithm
Graph's vertices are specified as a list
... | true |
11e7d3d78785ed89f7734d05608121ef8d58dd8e | betteridiot/biocomp_bootcamp | /basic_script.py | 413 | 4.75 | 5 | """Write a Python 'Hello, World' program.
A 'Hello, World' program is a program that prints out 'Hello, World' on the screen.
In addition to doing 'Hello, World', I want you to go a little further.
1. Print out 'Hello, World'
1. Save your partner's name as a variable
2. Print out 'Hello, <your partner's name>' by pa... | true |
55ae3800c673d4a662d51d3e272a25a8186458d1 | acm-kccitm/Python | /Class/Person.py | 2,885 | 4.3125 | 4 | class Person:
''' The class Person describes a person'''
count = 0
def __init__(self, name, DOB, Address):
'''
Objective: To initialize object of class Person
Input Parameters:
self (implicit parameter) - object of type Person
name - string
DOB - ... | true |
b3430f9aa7d8b084ea5f8f44a1af6723f12e98a4 | jsore/notes | /v2/python-crash-course/python_work/loops.py | 818 | 4.5625 | 5 | items = ['val1', 'val2', 'val3']
# basic syntax
for item in items:
print(item) # don't forget Python loves whitespace
print('this is outside the loop')
# ranges
for value in range(1, 5):
print(value)
# 1
# 2
# 3
# 4
# list from ranges
numbers = list(range(1, 6)) # [1, 2, 3, 4, 5]
# set step size for s... | true |
e3c3ff38d924f380917f5d5b48a755d1e708a06e | Sravya12379/walk2zero | /googlemaps.py | 2,089 | 4.3125 | 4 | import requests
def input_locations():
"""
This allows the user to input the locations of the origin and destination, assigns them to variables and returns
these variables.
:return: inputted origins and destination
"""
origin = input("Your location: ")
destination = input("Your destinatio... | true |
382c5bc9518497e6d3d972912c33c7cb93ef75d8 | HarrisonMS/JsChallenges | /Python/hackerrank/staircase.py | 301 | 4.125 | 4 | #!/bin/python3
import math
import os
import random
import re
import sys
# Complete the staircase function below.
def staircase(n):
spaces = n-1
stairs = 1
while n:
print(" "*spaces + '#'*stairs)
n -= 1
spaces -= 1
stairs += 1
print(staircase(6))
| true |
7271c2f2f3f3c02b743f365b3d203c9b2fc0085a | shinjita-das/python-learning | /prac.py | 848 | 4.125 | 4 | def calc(input1, input2, operator):
value = None
# Start here
# if else
# math operators
# how to compare strings in python
if operator == "+":
value = input1 + input2
elif operator == "-":
value = input1 - input2
elif operator == "*":
value = input1 * input2
... | true |
96627c0924c2a27c74ad4e6eef0bfe0ba369027c | sarahmarie1976/cs-guided-project-python-basics | /src/demonstration_03.py | 803 | 4.53125 | 5 | """
Challenge #3:
Create a function that takes a string and returns it as an integer.
how would we cast string to integer
We would instantiate an int object from the string data example --- int("10")
then it will return an integer -- 10
if we check the type(int("10"))
<class 'int'>
We can use the int() ... | true |
ed72de3aa6354a0e194df8e3ffeead2c69e5f379 | diminako/100-days-of-python | /day-03-conditionals/day-03.py | 2,425 | 4.25 | 4 | # conditionals
# If / Else statement
print('Welcome to the Roller Coaster!')
height = int(input("What is your height?\n"))
if height >= 100:
print('You may ride the roller coaster!')
else:
print('Grow up kid!')
print('Neat!')
print('----------------------')
# Code Challenge Odd or even check
num = int(input(... | true |
449c36aa7b4d056abb31ea4623d7d3d29ec3d14c | TheGrateSalmon/Side-Projects | /Collatz Conjecture.py | 1,048 | 4.1875 | 4 | # Collatz Conjecture (3n+1)
# performs the 3n+1 algorithm for any positive integer
from time import *
def main():
number = int(input('Input any positive integer or "0" to quit: '))
while number < 0:
number = int(input('That is not a valid input. Please input any positive integer or "0" t... | true |
a43bf45cbc1d6a88280ed77efabc85d471978f6f | uisandeep/ML-Journey | /python/variablescope.py | 1,923 | 4.28125 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun May 31 14:57:34 2020
@author: sandeepthakur
"""
# Example 1
# Although x and y are two different variables, it will have same memory addess
x=20
y=20
print(id(x))
print(id(y))
print("-----------------------------------------------------")
# Exampl... | true |
265c8b5a4d091d1c9ee4066dc4ecf06270eb7205 | jjliun/Python | /Interactive/project1.py | 2,495 | 4.3125 | 4 | #!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
# Filename : project1.py
# Author : Yang Leo (JeremyRobturtle@gmail.com)
# Last Modified : 2014-04-01
'''Demo of rock-paper-scissors-lizard-Spock
'''
# The key idea of this program is to equate the strings
# "rock", "paper", "scissors", "lizard", "Spock" to n... | true |
f15e22655fc5e6225dd18018e07cba2b0089aa93 | Vansh-Arora/InteractWithOS | /diff-file-operations/workingOnFiles/last_modification_date.py | 525 | 4.125 | 4 | #!/usr/bin/env python
import os
import datetime
def file_date(filename):
# Create the file in the current directory
file = open(filename,"w")
file.close()
timestamp = os.path.getmtime(filename)
# Convert the timestamp into a readable format, then into a string
date = str(datetime.datetime.fromtimestamp(ti... | true |
8c74e8c55d53a970b46fde0f4305fe7da4988c07 | cddas/python27-practice | /exercise-6.py | 427 | 4.34375 | 4 | user_string = raw_input("Enter a name for Palindrome check : ")
list_string = []
reverse_list_string = []
for letter in user_string:
list_string.append(letter)
reverse_list_string = list_string[:]
reverse_list_string.reverse()
if (list_string == reverse_list_string):
print("The entered string " + user_strin... | true |
76fb884a8571e0cc23d7c1a122f78e3cc386d6c2 | Simrang19/sort_n_search | /searching/bisect_library.py | 553 | 4.125 | 4 | # bisect : python library to use binary search
# bisect left : find the leftmost possible index to insert in the list such that list is still sorted.
# bisect right : find the rightmost possible index to insert in the list such that list is still sorted.
import bisect
li = list(map(int, input().split()))
while True:... | true |
df93e0dfc98976e5101dcf53d6cdad6044d643ea | 596050/DSA-Udacity | /practice/data-structures/stacks/reverse-stack.py | 347 | 4.125 | 4 | from stack import *
def reverse_stack(stack):
"""
Reverse a given input stack
Args:
stack(stack): Input stack to be reversed
Returns:
stack: Reversed Stack
"""
reversed_stack = Stack()
for i in range(stack.size()):
item = stack.pop()
reversed_stack.push(item)
... | true |
2eb8ef40c03c083f60841c7e63e6043792a2fdc1 | 596050/DSA-Udacity | /practice/data-structures/recursion/string-permutations.py | 1,148 | 4.1875 | 4 | def permutations(string):
"""
:param: input string
Return - list of all permutations of the input string
TODO: complete this function to return a list of all permutations of the string
"""
return _permutations(string, 0)
def _permutations(string, index):
if index >= len(string):
ret... | true |
ac702a3e7956293a0f38a414a3b45a22348de3e5 | Aditya7256/Demo | /join sets.py | 1,348 | 4.53125 | 5 | # The union() method returns a new set with all items from both sets:
set1 = {"a" "b", "c"}
set2 = {1, 2, 3}
set3 = set1.union(set2)
print(set3)
# The update() method inserts the items in set2 into set1:
set1 = {"a", "b", "c"}
set2 = {1, 2, 3}
set1.update(set2)
print(set1)
# The intersection_update() me... | true |
61e42234117d666ae39fe3783e82a85ffcb07813 | Aditya7256/Demo | /join List.py | 431 | 4.1875 | 4 | # Join two list
list1 = ["Apple", "banana", "mango"]
list2 = [4, 7, 3]
list3 = list1 + list2
print(list3)
# append to list2 into list1
list1 = ["mango", "orange", "pineapple"]
list2 = [3, 4, 25, 6]
for x in list2:
list1.append(x)
print(list1)
# use the extend() method to add list2 at end of list1
... | true |
78b733b769bdba9af2c2676c6ec564442c608fb5 | jmvbxx/happiness | /happiness_words.py | 823 | 4.25 | 4 | # This this program does two things:
#
# 1. Create a dictionary based on the happiness word list (AFINN-111.txt)
# 2. Prompts the user to choose a word and returns the value of that word
import re
words_dict = {}
# Generate dictionary from word list
with open("AFINN-111.txt") as words:
for line in words:
... | true |
a3cc9d25bd458d2c080c60a4b15aa10d5cb4563b | SamanthaCorner/100daysPython-DAY-5 | /adding_evens.py | 618 | 4.25 | 4 | """
100 days of Python course
DAY 5
"""
# calculate the sum of all the even numbers from 1 to 100,
# including 2 and 100: using the for ... in range loop
# approach using range 2, 101 and stepping by 2
even_sum = 0
for number in range(2, 101, 2):
even_sum += number
print(even_sum)
# a different appro... | true |
303698b606fe853364454dc666a8414eb803b920 | UCD-pbio-rclub/Pithon_Michelle.T | /pithon_07112018/0711_ex3.py | 1,178 | 4.125 | 4 | #3. Demonstrate inheritance by importing your class "Organism" from problem 2.
#Use it to create a new class called "LongOrganism" which inherits "Organism" and
#modifies it by adding any other attributes that may be significant about an organism
#(ie ploidy, genome size, region). Write new methods which allow a use... | true |
713737d145b1f751736a35aa7556e1482bf68e63 | yashshah4/Data-Science-Projects | /Miscellaneous/charactercount.py | 630 | 4.21875 | 4 | #The following module helps prettify the printout of a dictionary
#This module includes pprint() & pformat() to improve what print() generally offers
import pprint
#Asking for a text input from the user and saving it as a string
message = str(raw_input("Enter a text : "))
#Declaring a dictionary to count characters
cou... | true |
e4fe8c8df4a778d3c73c3193df5e5995cf80029c | jovannovarian1117/stephanusjovan | /drivingsimulatorstephj.py | 1,255 | 4.3125 | 4 |
# declare data for inputs
# initial velocity set to 0
u = 0
time = 0
velocity_data = 0
# user have to input the time below
t_input = int(input("Input time spent on the road"))
# user have to input their acceleration below
a = int(input("Input acceleration"))
# user have to input distance travel below
... | true |
68017376126391b4e4a4dae814825fdc903209ad | nconstable2/constable_n_python | /conditions.py | 800 | 4.34375 | 4 | # print a message to the terminal window
print("Rules that govern the state of water")
# set up a variable to hold the temp we input
current_temp = False
while current_temp is False:
# MAKE THIS A NUMBER!!
x = current_temp
current_temp = x
# see what current temp is
print("you input:", x)
# if... | true |
32560b22b72e04fd4c5d74538331c5101701df96 | sridhar29k/interview-task | /Task_2_virtusa.py | 706 | 4.15625 | 4 | ##Seating Arrangement. You have n students and n chairs in an exam hall. n/3 students are writing
##Maths, n/3 are writing physics and n/3 are writing chemistry. The n chairs are arranged in two
##rows, with n/2 in each row. Write an algorithm to make sure no two maths students sit either
##next/in front/behind of a... | true |
0ac4c535cf8c69463dcb5527747842510ae2318e | emerick23/python-control-flow-lab | /exercise-6.py | 1,536 | 4.53125 | 5 | # exercise-06 What's the Season?
# Write the code that:
# 1. Prompts the user to enter the month (as three characters):
# Enter the month of the season (Jan - Dec):
# 2. Then propts the user to enter the day of the month:
# Enter the day of the month:
# 3. Calculate what season it is based upon this chart:... | true |
9fe75a4cd0e11f1266cb257deaf339ac3575e24a | Sam40901/Variables | /assignment development exercise 1.py | 556 | 4.25 | 4 | print("hello, this program will ask you for two numbers, divide one by the other, give you the integer and the variable.")
number_1 = int(input("please enter your first number: "))
number_2 = int(input("please enter your second number: "))
number_integer = number_1 // number_2
number_remainder = number_1 % n... | true |
61d764d8419883b424ddedacee128a00621d22cf | pamelot/poem-word-count | /calculator.py | 1,461 | 4.375 | 4 | """
calculator.py
Using our arithmetic.py file from Exercise02, create the
calculator program yourself in this file.
"""
from arithmetic import *
def main():
# This is where the user can input the calculation.
# This will be a series of if statements for determining which function to call.
cond = T... | true |
9cf59ca6e5ef627197a86a2bb92140e88d0242ff | derekforesman/CMPSC-131 | /Python/apr_calculator.py | 630 | 4.1875 | 4 | #!/usr/bin/env python3
deposit = float(input("What is the amount you will be depositing?\n")) # get the amount to be deposited
apr = float(input("Please enter the APR for the account. For example (2) will be read as 2% or 0.02\n")) # get the percent APR
years = int(input("How many years will it gain interest?\n")) # g... | true |
45120d9c4d2adcbe72d170ec14a1908e512cd132 | aallooss/CSquared-2021 | /2_Whats_your_name.py | 217 | 4.125 | 4 | # authored by >Haden Sangree< for >Coding with Character Camp<
# Lesson 2
# CHALLENGE: Try changing the question and what your print.
name = input("Whats your name? ")
print("Your name is " + name)
#challenge
| true |
22d44e8410c0f7f7cc3696f2ae60b39c43bddccb | hudaquresh/pythonDSRune | /sortingAndSearching/sorting/insertion.py | 461 | 4.1875 | 4 | '''Implementing an insertion sort algorithm.'''
def insertionSort(aList):
# insertion sort
for index in range(1, len(aList)):
currentValue = aList[index]
position = index
while position > 0 and aList[position-1] > currentValue:
aList[position] = aList[position-1]
position = position-1
aList[positio... | true |
9f4225b7fbaf84b3d97360f38a12d72fb4c1d4b2 | arleybri18/holbertonschool-higher_level_programming | /0x01-python-if_else_loops_functions/1-last_digit.py | 607 | 4.125 | 4 | #!/usr/bin/python3
import random
number = random.randint(-10000, 10000)
if number < 0:
print("Last digit of {0} is {1} and is less than 6 and not 0".format
(number, -(-number % 10)))
else:
if (number % 10) > 5:
print("Last digit of {0} is {1} and is greater than 5".format
(number... | true |
9808fd61460fd7caf2657561f8b172590def8396 | arleybri18/holbertonschool-higher_level_programming | /0x06-python-classes/5-square.py | 1,357 | 4.4375 | 4 | #!/usr/bin/python3
class Square:
"""Class with a instance private attribute, with optional value 0
validate type and value > to 0, send a message Error using raised
and define a method to calculate area of square
"""
def __init__(self, size=0):
"""init method
Args:
si... | true |
35e4f85e35f97e1427b77f5c57632cc425eb18ac | IonesioJunior/Data-Structures | /Python/LinkedList/SingleLinkedList/RecursiveSingleLinkedList.py | 2,998 | 4.25 | 4 | #coding: utf-8
__author__ = "Ionesio Junior"
class RecursiveLinkedList(object):
''' Single Linked List in recursive implementation
Attributes:
data(optional) : data stored in this object
nextNode(RecursiveLinkedList) : next Recursive Node
'''
__data = None;
__nextNode = None;
def __init__(self,... | true |
f2fa0f0eb5bfcfbff341ee268ed6652d1f589ee7 | IonesioJunior/Data-Structures | /Python/Stack/Stack.py | 2,027 | 4.125 | 4 | #coding:utf-8
__author__ = "Ionésio Junior"
class Stack():
""" Stack Structure Implementation
Attributes:
stackList[] = list of elements in stack
size(int) = size of stack
top(int) = index of top
"""
__stackList = None;
__size = None;
__top = None;
def __init__(self,size = 10):
'''' Stack Con... | true |
020210178bbd278da6d41b09c26ea74d5bca0c84 | IonesioJunior/Data-Structures | /Python/Queue/SimpleQueue.py | 2,244 | 4.4375 | 4 | #coding: utf-8
__author__ = "Ionésio Junior"
class SimpleQueue():
''' Implementation of simple queue data structure
Attributes:
queueList[] : list of elements in queue
size(int) : size of list
tail(int) : index of queue tail
'''
def __init__(self,size = 10):
''' Constructor of Simple Queue initi... | true |
d3659a72ef9816bee8d3c05c1c15f73fb2fb89e8 | khemasree/CSEE5590_Lab | /Lab1/Source/Lab1/lab2a.py | 994 | 4.21875 | 4 | input = input("Please enter the sentence")
# Initialize all the variables with default values
individualwords=input.split()
wordset=individualwords
longestword = ''
reversesen = ''
print(wordset)
# For even number of words print the middle two words
if len(wordset) % 2 == 0 :
print("Middle Words are: ["+individua... | true |
5677689f850e6b426c4a88976b4bd1e9e6c07aa2 | SillAndrey/training | /next_factorial.py | 876 | 4.25 | 4 | def next_factorial(n):
'''
find all Prime Factors (if there are any) and display them.
program find prime numbers until the user chooses to stop asking for the next one.
'''
Ans = []
d = 2
while d * d <= n:
if n % d == 0:
Ans.append(d)
n //= d
else:
... | true |
6ffe61b87d42a3734848c0cf33a315be33da25d4 | jan-nemec/ATBSWP | /03_exception_zero_divide.py | 1,008 | 4.28125 | 4 | # Errors can be handled with try and except statements.
# The code that could potentially have an error is put in a try clause.
# The program execution moves to the start of a following except clause if an error happens.
# You can put the previous divide-by-zero code in a try clause
# and have an except clause contain... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.