blob_id
stringlengths
40
40
repo_name
stringlengths
5
127
path
stringlengths
2
523
length_bytes
int64
22
3.06M
score
float64
3.5
5.34
int_score
int64
4
5
text
stringlengths
22
3.06M
cc19babd5a8b1698c5b1aca0dfdb29122ee2e494
seungmin001/programmers
/hash/전화번호목록.py
233
3.796875
4
def solution(phone_book): answer = True dict={} phone_book.sort() before='a' # 첫번째 for p in phone_book: if before in p: return False before=p return answer
2d30aaf0eddd3a054f84063e3d6971b4933097af
irosario1999/30days-of-python
/day_2/variables.py
1,014
4.125
4
from math import pi print("Day 2: 30 days of python") firstName = "ivan" lastName = "Rosario" fullName = firstName + " " + lastName country = "US" city = "miami" age = "21" year = "2020" is_married = False is_true = True is_light_on = False i, j = 0, 3 print(type(firstName)) print(type(lastName)) print(type(fullName...
f884b87a05f26d501e7c03a1076580bf5d3db646
eweisger/Diffie-Hellman-HTTP-Host-and-Client
/diffieHellmanHTTPServers/task2.py
3,817
3.515625
4
#Emma Weisgerber #CSCI 373: Intro to Cyber Security - Dr. Brian Drawert #Homework 2: Cryptography - 2/18/19 #----------------------------------------------------- #Program which implements the Affine substitution cypher #Uses the character set of ASCII code 32 through 126 for a total of 95 characters, and ignores the n...
34aa56f0a0d252b2aef9d420be28d23106725a3d
vlapparov/Ecole42
/Django/d01/ex00/var.py
550
3.734375
4
# coding: utf-8 # In[9]: # 42 est de type <class 'int'> # 42 est de type <class 'str'> # quarante-deux est de type <class 'str'> # 42.0 est de type <class 'float'> # True est de type <class 'bool'> # [42] est de type <class 'list'> # {42: 42} est de type <class 'dict'> # (42,) est de type <class 'tuple'> # set() es...
a6e227d28ed371a8516d468b9b870323a6144695
vs359268/pythonUtils
/01.pdf_split.py
943
3.578125
4
# -*- coding:utf-8 -*- # @Time : 2021/3/8 18:46 # @Author: Sun Hao # @Description: 根据页数切割pdf文件 # @File : 01.pdf_split.py from PyPDF2 import PdfFileReader, PdfFileWriter def split_single_pdf(read_file, start_page, end_page, pdf_file): #1.获取原始pdf文件 fp_read_file = open(read_file, 'rb') #2.将要分割的pdf内容格式化 p...
d0217754668282cca99a70d421775c2fa574c1c9
atreanor/FlightCalculator
/Aircraft.py
545
3.734375
4
class Aircraft: """ a class to store Airport objects """ def __init__(self, code, units, range): """ class constructor initialises variables with input """ self.code = code self.units = units self.range = range def get_range(self): """ method to retrieve aircraft ...
d64d1b8b956ba1bb55895093fe0b1bea1c240bea
lhwylpdpn/IIT_study
/cs430/cs430-greedy.py
1,573
3.703125
4
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import time class Q9(): def __init__(self,cell): self.cell=cell for r in self.cell: r.insert(0,1)#每行首加阻碍 r.append(1)#每行尾巴加阻碍 self.cell.insert(0,[1]*len(cell[0])) self.cell.append([1]*len(cell[0])) ...
ff3984153b82e47887a4621b85c660b5cd262916
n20084753/Guvi-Problems
/beginer/set-2/print-even-values-in-range.py
175
3.625
4
import sys m, n = [int(x) for x in raw_input().split(" ")] evenValues = [] for i in range(m+1, n): if (i & 1) == 0: evenValues.append(str(i)) print(' '.join(evenValues))
c0d3eda8788a772005f3c4d51d21c3454c6d2162
n20084753/Guvi-Problems
/beginer/set-6/60-fibonacci-series.py
241
3.6875
4
def fibo(n): if n < 2: return 1 if memo[n] != 0: return memo[n] memo[n] = fibo(n-2) + fibo(n-1) return memo[n] n = int(raw_input()) memo = [0 for i in range(n)] memo[0] = memo[1] = 1 fibo(n-1) print(" ".join(str(x) for x in memo))
ed8fb302f599d4f5f37e4cfa061fc60d1763cab3
n20084753/Guvi-Problems
/beginer/set-11/109-minimum-in-array.py
131
3.890625
4
values = [int(x) for x in raw_input().split(" ")] min = float('inf') for item in values: if item < min: min = item print(min)
274ff48adcbd3e8986f0e38ce819581137a82446
n20084753/Guvi-Problems
/beginer/set-5/43-strcat.py
159
3.609375
4
def myStrcat(s1, s2): s3 = '' for s in s1: s3 += s for s in s2: s3 += s return s3 s1, s2 = [x for x in raw_input().split()] print(myStrcat(s1, s2))
edf44d91616f17cec7f142b595b81661c6115386
n20084753/Guvi-Problems
/is-alphabet.py
108
3.5
4
import sys input = sys.stdin.readline().rstrip() if input.isalpha(): print("Alphabet") else: print("No")
db5b84c9356adf31355f0eb0656752405a4ea3fa
n20084753/Guvi-Problems
/beginer/set-7/64-is-sum-odd-or-even.py
134
3.78125
4
n, m = [int(x) for x in raw_input().split(" ")] print("even" if (n & 1 == 0 and m & 1 == 0) or (n & 1 != 0 and m & 1 != 0) else "odd")
4bfb363c4d4daa59ab642e6280384a5fa38c0185
n20084753/Guvi-Problems
/beginer/set-3/is-numeric.py
295
3.859375
4
def isNumber(str): if str[0] != '-' and not str[0].isdigit(): return False if str[0] == '-' and len(str) == 1: return False for i in range(1, len(str)): if not str[i].isdigit(): return False return True input = raw_input() if (isNumber(input)): print("Yes") else: print("No")
3d84235eed2e481dde2e5a4e0822e9ed72a8016e
n20084753/Guvi-Problems
/beginer/set-8/80-print-odd-digits-in-number.py
162
3.6875
4
n = int(raw_input()) digits = [] while n > 0: r = n % 10 if r & 1 != 0: digits.append(str(r)) n = n / 10 digits = reversed(digits) print(" ".join(digits))
a78a83d12fcfe61a67491e5a23ff2a6ebadb1b56
wercabaj/BankingSystem
/main.py
7,409
3.828125
4
import random import sqlite3 conn = sqlite3.connect('card.s3db') cur = conn.cursor() cur.execute('CREATE TABLE IF NOT EXISTS card (id INTEGER, number TEXT, pin TEXT, balance INTEGER DEFAULT 0);') conn.commit() def menu(): print("""1. Create an account 2. Log into account 0. Exit""") ...
d639304757ad0c96c4c57ad799392ab1e8e104f0
quangloan17/hocThayTung
/1.T6/15-06-lambda/tham_khao/h2.py
270
3.640625
4
x = input('nhập vào xâu dạng nhị phân = ') def changeofNumber(x): change = 0 p = len(x)-1 for i in range(len(x)): change += int(x[i]) * pow(2,p) p -= 1 return change print('chuyển đổi được',changeofNumber(x))
db87f57e50c33387e92206404aed0542ea459170
quangloan17/hocThayTung
/1.T6/05-06-vong-lap2/1_vi_du_ho_ten.py
357
3.703125
4
#todo: #Nhập vào: họ, tên đệm, tên #in ra: Họ và tên đầy đủ: ho = input('Họ bạn là gì: ') ten_dem = input('Tên đệm của bạn là gì: ') ten = input('Tên của bạn là gì: ') print(f'Tên của bạn đầy đủ là: {ho} {ten_dem} {ten}') print(f'Tên của bạn đầy đủ là: {ho}, {ten_dem}, {ten}')
a1c3bf809dfdf8569dc46b061b93842761fef1ad
quangloan17/hocThayTung
/1.T6/05-06-vong-lap2/bai_tham_khao/Trần Thành Công/BVN1buoi4.py
155
3.859375
4
str1=input("Input string: ") count=0 for i in range(len(str1)): if str1[i]!=" ": count+=1 print("Số ký tự có trong string:",count)
51d94b3471a96b5bcb2afde6bf7f3d9b90458cf4
quangloan17/hocThayTung
/1.T6/05-06-vong-lap2/1_thap_hanoi.py
323
3.828125
4
def hanoi(N , src, dst, temp): if N == 1: print('Chuyển đĩa 1 từ cọc', src, 'sang cọc ', dst) return hanoi(N-1, src, temp, dst) print('Chuyển đĩa' , N , 'từ cọc', src, 'sang cọc ', dst) hanoi(N-1, temp, dst, src) N = 4 hanoi(N, 1, 3, 2)
33bc583e75f8bf0ca967a5ce0e40b30c71450175
quangloan17/hocThayTung
/1.T6/01-06-vong-lap/bang_cuu_chuong2.py
98
3.546875
4
for j in range(2,11): print('') for i in range(2,11): print(f'{j}*{i}={j*i}')
c32ee8069bcc8369b6a760620d15a221c480638c
vipinkvpk/Data-Visualization-with-Python-project
/task1.py
246
3.609375
4
import pandas as pd import matplotlib.pyplot as plt df = pd.read_json (r'./rain.json') print(df) print("df statistics: " ,df.describe()) df.plot(x='Month', y ='Temperature') df.plot(x='Month', y = 'Rainfall') plt.show()
d84294ca3dea0a25671fcc4a5f97b9b958f5ee1e
MashodRana/NLP
/Speech_to_TextBangla_and_POS_tagger/posTagger.py
17,468
3.609375
4
# -*- coding: utf-8 -*- """ Created on Wed Feb 7 19:44:09 2018 @author: Sagar Hossain """ """ it takes a word then gives which parts of speech it is as a tuple as (word,nameOfpos) """ from xml.dom import minidom nouns=[] prons=[] verbs=[] adj=[] adv=[] conj=[] def gettinNouns(): xmldoc = mi...
ef8f21afbcc9782be8d477249df0b998601e6f75
Jonny-Full/CWI-Transmissivity
/data_to_csv.py
5,245
3.703125
4
# -*- coding: utf-8 -*- """ This module was created to hold any code that transforms our data into csv files. This module has two functions: Functions ----------- calculated_data_to_csv: This function take the data from transmissivity calculated and conductivity_calculated and converts the data into a csv fil...
b92fe200fc7faa8bbe20f0a87e032d78000dc598
M4R14/mini-project-network
/gameXO.py
1,568
3.859375
4
import random board = [0,1,2, 3,4,5, 6,7,8] def show(): print board[0],'|',board[1],'|',board[2] print '---------' print board[3],'|',board[4],'|',board[5] print '---------' print board[6],'|',board[7],'|',board[8] def checkLine(char, spot1, spot2, spot3): if board[spot1] ==...
55ae7ae4ad64c690800e9d2a9d37684eb3069bb9
andkoc001/pands-problem-set
/06-secondstring.py
1,379
4.15625
4
# Title: Second Strig # Description: Solution to problem 6 - program that takes a user input string and outputs every second word. # Context: Programming and Scripting, GMIT, 2019 # Author: Andrzej Kocielski # Email: G00376291@gmit.ie # Date of creation: 10-03-2019 # Last update: 10-03-2019 ### # Prompt for the user;...
721bac447024b95c310b6d18d62e24d6b552d491
thespacemanatee/10.009-ESCAPE-Text-RPG
/Submission/Modular Version/map.py
6,920
3.5625
4
##### MAP ##### """ a1 a2 a3 # PLAYER STARTS AT b2 ---------- | | | | a3 ---------- | | X| | b3 ---------- | | | | c3 ---------- """ LOCATION = '' DESCRIPTION = 'description' INSPECT = 'examine' SOLVED = False TASK = 'task' UP = 'up', 'north' DOWN = 'down', 'south' LEFT = 'left', 'west' RIGHT = 'right', 'east'...
0474865bcab2bf2ee00e506cffa611d1a5220a42
culeJUN/BaekJoon
/07.문자열/07-04.py
143
3.53125
4
time = int(input()) for i in range(time) : num, s = input().split() for i in s : print(i * int(num), end = '') print()
de7395aa845bb9f39ade95d449fe3a5bf9c5f93a
culeJUN/BaekJoon
/10.재귀/10-02.py
151
3.71875
4
def fibo (i) : if i == 0 : return 0 if i == 1 : return 1 return fibo(i - 1) + fibo(i - 2) x = int(input()) print(fibo(x))
fd138e19e420985a58e97501cc239e3e2bb13490
culeJUN/BaekJoon
/09.기본 수학 2/09-10.py
99
3.796875
4
import math r = float(input()) print('%0.6f' % float(r*r*math.pi)) print('%0.6f' % float(r*r*2))
f5b1056660c96894a31e82f852d8a666e0e6e661
czqzju/algorithms
/Interview Preparation Kit/Dynamic Programming/Abbreviation.py
1,027
3.734375
4
#!/bin/python3 import math import os import random import re import sys # Complete the abbreviation function below. def check(a, b): if len(b) > len(a): return False elif len(b) == len(a): if len(b) == 0 or b == a.upper(): return True else: return False els...
032eb3a8741d3be508427785106fdd1abb0b5a0a
czqzju/algorithms
/Graph Theory/Roads_in_HackerLand.py
2,452
3.515625
4
#!/bin/python3 #https://www.hackerrank.com/challenges/johnland/problem pypy3 import os import sys # # Complete the roadsInHackerland function below. def findParent(node, parent): while not node == parent[node]: node = parent[node] return parent[node] def updateParent(node, parent, p): while parent[node...
bedb53f76cdcbe631f2511178429441760f6731d
MukulJuneja07/Python_files
/MultiThreading.py
301
3.609375
4
import threading x=0 y=0 def func1(): global x for i in range(100000000): x=x+1 def func2(): global y for i in range(100000000): y=y+1 Th1 = threading.Thread(target=func1) Th2 = threading.Thread(target=func2) Th1.start() Th2.start() Th1.join() Th2.join() print(x,y)
8b443f8883bf05a1d542d03c61a9f33f2e0496e6
MukulJuneja07/Python_files
/FactorsofNo.py
523
3.5625
4
x=int(input("Enter any number")) fac=1 for i in range(1,x+1): fac=fac*i print(fac) # # from netrc import netrc # n=int(input("Enter range for fibo series")) # x=0 # y=1 # print(x) # print(y) # next=0 # while(next<=n): # next=x+y # print(next) # x=y # y=next # print(next) # i=0 # x=0 # y=1 # wh...
1dc7162067d1497d393bec7d73920b5663f7bdfb
liwasai/MST
/1.py
1,315
3.8125
4
1.Python中pass语句的作用是什么? pass语句什么也不做,一般作为占位符或者创建占位程序,pass语句不会执行任何操作。 2.Python是如何进行类型转换的? Python提供了将变量或值从一种类型转换成另一种类型的内置函数。比如int函数能够将符合数学格式数字型字符串转换成整数。否则,返回错误信息。 3.Python是如何进行内存管理的? Python引用了一个内存池(memory pool)机制,即Pymalloc机制(malloc:n.分配内存),用于管理对小块内存的申请和释放。 4.dict 的 items() 方法与 iteritems() 方法的不同? items方法将所有的字典以列表方式返回...
afb64292cd8438dcbcee167ac2d27ff275d84457
paul-madut/ISC3U-Unite3-04-Python
/number_comparer.py
563
4.09375
4
#!/usr/bin//env python3 # Created on: September 2019 # Created by: Paul Madut # This is the a program used as a random number generator def main(): # This function does plays a game # Input user_number = int(input("Give a number: ")) print(" ") # Process if user_number < 0: print("Yo...
e68f38514b48634019920a756c58e84d22afdd27
abjose/misc
/maxflow.py
3,191
3.625
4
import math nodes = 0 # number of nodes CapMatrix = None # capacity matrix FlowMatrix = None # flow matrix MaxFlow = 0 # flow to T nodeArray = [ ] pathList = [ ] usedList = [ ] def initialize(): global nodes global CapMatrix global FlowMatrix global MaxFlow print "Please enter the number of nodes...
70e3141a254c254d933e6bba2cae77e73ec03822
abjose/misc
/stuff.py
3,091
3.71875
4
def dissimilarity(s1, s2): # return dissimilarity of two strings assert len(s1) == len(s2) return sum([1 if s1[i]!=s2[i] else 0 for i in range(len(s1))]) def compare_substrings(n, s1, s2): # given two substrings, find all similar-enough matches without shifts assert len(s1) == len(s2) if n > ...
a73453b34e88c4142ee0b676303553e307913987
kirigaikabuto/distancelesson2
/lesson4/12.py
787
3.734375
4
s="Привет меня зовут Ерасыл мне 22.Я живу в городе Алматы.Алматы построили в 18 веке" # 1) делим по точкам ["Привет Привет зовут Ерасыл мне 22","Я живу в городе Алматы","Алматы построили в 18 веке"] # 2) делим по пробелам одновременно все закидывать в общий массив # 3) ['Привет','Привет'....'живу'] # 4) разбирать на чи...
4fd102d6b6b48cadd7bcd5d89b8ac9c6fedb3395
kirigaikabuto/distancelesson2
/lesson12/5.py
324
3.625
4
from myutils import * persons=[ { "name":"yerassyl1", "year":1998 }, { "name":"yerassyl2", "year":1997 }, { "name":"yerassyl3", "year":1999 }, ] ages = list(map(getAge,persons)) # ages=[] # for i in persons: # realage = getAge(i) # ages.append(realage) print(a...
b2b201f1e2f0bf41f056631465aaf22fcef33782
kirigaikabuto/distancelesson2
/lesson3/4.py
213
3.578125
4
arr=[] print(arr,len(arr)) arr.append(10) print(arr,len(arr)) arr.append(20) print(arr,len(arr)) arr.append(30) print(arr,len(arr)) arr.append(40) print(arr,len(arr)) sumi = arr[0]+arr[1]+arr[2]+arr[3] print(sumi)
d6a0b0eefc33cb07b658f265d86439b9b704ef23
kirigaikabuto/distancelesson2
/lesson3/17.py
395
4
4
# надо найти максимальный элемент массива # используя цикл for arr=[100,233,140,900] maxi=arr[0] n = len(arr) for i in range(n): if maxi<arr[i]: maxi=arr[i] print(maxi) # if maxi<arr[0]: # maxi = arr[0] # if maxi<arr[1]: # maxi = arr[1] # if maxi<arr[2]: # maxi = arr[2] # if maxi<arr[3]: # ...
366e59537c5d5373bf43ca909bbee2442e0e5502
kirigaikabuto/distancelesson2
/lesson6/7.py
192
3.578125
4
arr=[120,232,445,678] n = len(arr) # print(arr[0]) # print(arr[1]) # print(arr[2]) # print(arr[n-1]) for i in range(n): print(i,arr[i]) # for i in arr: # if i > 130: # print(i)
98c0c4525dd0bff2f7702c1388ce18e556c43c7f
kirigaikabuto/distancelesson2
/lesson7/11.py
212
3.5
4
# d={ # "name":"product1", # "price":1000 # } # print(d) # d['sale']=0.5 # d['name']="prdict12312" # print(d) product={} product['name']="sdsdd" product['price']=1000 product['price']=12300 print(product)
8cf25e3b49f99dac1527133b3789182424c4cdb0
kirigaikabuto/distancelesson2
/lesson2/9.py
81
3.78125
4
num = int(input()) if num==5 or num==10: print("OK") else: print("Error")
4635f47746cd281455ba2cce088f1a6f5de381b7
kirigaikabuto/distancelesson2
/lesson4/1.py
158
3.765625
4
s = "Hello world" #char #str много char n = len(s) # for i in range(n): # print(s[i]) # for i in s: # print(i) # s[0]="123" s = s+"Yerassyl" print(s)
df9b8f3cf31fb8797b7253807969324ba9142416
kirigaikabuto/distancelesson2
/lesson2/6.py
342
3.890625
4
# 0<=summa<50000 1.3 # 50000<=summa<100000 1.6 # 100000<=summa<150000 1.9 summa = int(input()) percent=0.0 if summa>=0 and summa<50000: percent = 1.3 elif summa>=50000 and summa<100000: percent = 1.6 elif summa>=100000 and summa<150000: percent = 1.9 else: print("Error") total_sum = summa+summa*percen...
95d97d25e6298ae09a5f5892537dcdb4b7151358
utep-cs-systems-courses/os-shell-seanraguilar
/shell/myPipe.py
1,616
3.828125
4
import os from myRedirect import redirect from shell import executeCommands import pipe '''This is the pipes method that take output of one method as input of another for example: output | input''' def pipeInput(args): left = args[0:args.index("|")] # This gets data of left side of pipe right = args[len(left)...
b9997d5c2b81bd243fb326d6a24ea227ab6d1503
mkrug6/Examining-Enron-Emails-Using-Machine-Learning-Techniques
/analyze.py
1,217
3.734375
4
def analyze(data): """ Let's take a deeper look into the data """ persons = data.keys() POIs = filter(lambda person: data[person]['poi'], data) print('List of All People in the Data: ') print(', '.join(persons)) print('') print('Total Number of People:', len(persons)) print('') ...
3cc0fcee11a7eea3411f26afebac5fea6eebd6b1
BlackJimmy/SYSU_QFTI
/mateig.py
427
4.15625
4
#this example shows how to compute eigen values of a matrix from numpy import * #initialize the matrix n = 5 a = zeros( (n, n) ) for i in range(n): a[i][i] = i if(i>0): a[i][i-1] = -1 a[i-1][i] = -1 #print the matrix print "The matrix is:" for i in range(n): print a[i] #compute the eigen ...
2312bec70f516192b18b7e65848770283c15ef7a
Doyun-lab/codeup
/codeup_1156.py
111
3.6875
4
def distinct(x): if x % 2 == 0: return "even" else: return "odd" print(distinct(3)) print(distinct(4))
89a737abdb4b1c44fdb2dd2243d034d8069139bf
Nnett0523/PYMI_Ex
/ex7_4.py
1,330
3.59375
4
#!/usr/bin/env python3 def solve(text): '''Thực hiện biến đổi input: [a, abbbccccdddd, xxyyyxyyx] output: [a, abb3cc4dd4, xx2yy3xyy2x] Giải thích: Những chữ cái không lặp lại thì output giữ nguyên chữ cái đó. Những chữ cái liên tiếp sẽ in ra 2 lần + số lần lặp lại liên tiếp. Đây là một ...
659bfbd1e43478b563d20646b9a0517536635911
nestordemeure/flaxOptimizersBenchmark
/flaxOptimizersBenchmark/training_loop/tools/dict_arithmetic.py
3,347
4.03125
4
import copy import numbers import math #---------------------------------------------------------------------------------------- # HIGHER ORDER FUNCTIONS def map_dict(d, func): """ applies func to all the numbers in dict """ for (name,value) in d.items(): if isinstance(value, numbers.Number): ...
82d2bbbc5b31db2f03c35db811650df07918a2b6
19rixo75/homeWork
/count_world_text.py
1,701
3.59375
4
# Домашнее задание: # Написать программу, которая открывает заданый пользователем файл, считает количество слов, и количество уникальных # слов (если это слово уже посчитанно, то второй раз не считает) # Примеры: # Программа = программа # Программа, = программа # Рыбачить и рыбачит это разные слова # Т.е. Знаки препина...
7d06e324ef8334edbc2da72b12532772b55a7432
gogo7654321/python_gamer
/lower to upper in lists.py
204
4.09375
4
name = [] print ("enter 5 lowercase sentences and i will convert them to uppercase") for x in range (1,6): a = str(input()) name.append(a) for x in name: upper = (x.upper()) print(upper)
55d55eac8e4fc97d2ded50aeea233c4c568f562d
gogo7654321/python_gamer
/name to age.py
514
3.859375
4
while ("true") print ("enter any close family members name and I will figure out their age") name = str(input()) #print(name) if (name.lower() == 'sunny'): print ("you are 42 years old. That's really old!") if (name.lower() == 'devika'): print ("you are 36 years old. Thats decent age.") ...
84cf0bb4403ac3a763b0d0c4f2f6b5bde775b447
chenjiahuan262821/LearnPy
/python_100_day/day16_sorting/temp.py
221
3.875
4
def Factorial(n): if n == 0 | n == 1: return 1 return Factorial(n-1)*n # print(Factorial(6)) def Fibonaqi(n): if n == 1: return 0 if n == 2: return 1 return Fibonaqi(n-1)+Fibonaqi(n-2) print(Fibonaqi(30))
a306575a2d00dc29c07aa7e14f5f1b86f6a67169
chenjiahuan262821/LearnPy
/python_100_day/day16_sorting/selectionSort.py
503
3.859375
4
''' 选择排序的算法 先设置minIndex为i,对应值为list[i] 然后从i+1开始往后遍历找出最小的值,并将minIndex设置为该值的位置 最后将i位置与minIndex位置的数值互换,就得到第i大的值 ''' a = [6,5,4,3,2,1,10,8,9,8.1] def selectionSort(list): for i in range(len(list)): minIndex = i for j in range(i+1, len(list)): if list[j] < list[minIndex]: minIndex = j list[i], list[minIndex] ...
2441f1675f6d6269601c6781bd7ff8d285d28402
chenjiahuan262821/LearnPy
/python_100_day/day9_class2/staticmethod.py
1,246
4.0625
4
from math import sqrt class Triangle(object): def __init__(self, a, b, c): self._a = a self._b = b self._c = c @staticmethod #静态方法,说明接下来的这个方法是绑定在类上的 def is_valid_static(a, b, c): return a + b > c and b + c > a and a + c > b #有效的话会返回True @classmethod #类方法,第一个参数约定名为cls,代表当前类相关的信息 def is_valid_class(cls...
0755dc776d103520af3d8d10fc16be3fe7b19d56
siots/analysis_noti_data
/parser_lib/csvhelper.py
12,606
3.5
4
#-*- coding: utf-8 -*- import csv,codecs import stdtable from datetime import datetime def csv_parser(filename, printable=False): csv_list = [] with open(filename, 'r') as csvfile: reader = csv.reader(csvfile) for row in reader: row_list=[] for col in row: ...
f9af5624fe12b3c6bd0c359e5162b7f9f48234e7
Yarin78/yal
/python/yal/fenwick.py
1,025
3.765625
4
# Datastructure for storing and updating integer values in an array in log(n) time # and answering queries "what is the sum of all value in the array between 0 and x?" in log(n) time # # Also called Binary Indexed Tree (BIT). See http://codeforces.com/blog/entry/619 class FenwickTree: def __init__(self, exp): ...
d7d9550e9acb11727564ba122a9427139f47a5e3
ode2020/bubble_sort.py
/bubble.py
388
4.1875
4
def bubble_sort(numbers): for i in range (len(numbers) - 1, 0, -1): for j in range (i): if numbers[j] > numbers[j+1]: temp = numbers[j] numbers[j] = numbers[j+1] numbers[j+1] = temp print(numbers) numbers = [5, 3, 8, 6, 7, 2] bubble_s...
a22b933bbaf3e12d053af0f4dc750c9b0d1338ed
zhaoyangkun/python-eight-sort
/heap_sort.py
1,264
3.78125
4
def adjust(arr, parent, n): """ 调整二叉树 :param arr: 列表 :param parent: 父节点下标 :param n: 列表长度 """ temp = arr[parent] # 保存父结点的值 child = 2 * parent + 1 # child 指向左孩子 while child < n: if child + 1 < n and arr[child] < arr[child + 1]: # 若右孩子存在且大于左孩子,将 child 指向右孩子 child ...
2a7cb0cb80e8207467f586bcba29401ed2e71840
Romumrn/Pipeline_variant_RDP
/script/.docker_modules/csv_checkdesign_python/0.0.1/check_design_chip_quant.py
2,465
3.65625
4
#!/usr/bin/env python3 import sys design=sys.argv[1] ## input csv file design_checked=sys.argv[2] ## output csv file: same as design input but make sure there is no space in the row ## avoid error in nextflow process def csv_parser(csv, csv_out): ERROR_STR = 'ERROR: Please check de...
0dc21795e938f7dbfcd47124654d8a002a790a65
ravalrupalj/BrainTeasers
/Edabit/Get_Student_Top_Notes.py
1,025
3.53125
4
#Create a function that takes an list of student dictionaries and returns a list of their top notes. If student does not have notes then let's assume their top note is equal to 0. def get_student_top_notes(lst): ans=[] for i in lst: if len(i['notes'])>0: ans.append(max(i['notes'])) e...
aa83f5258b80e1c403a25d30aeb96f2a8125ec73
ravalrupalj/BrainTeasers
/Edabit/Day 3.3.py
459
4.125
4
#Get Word Count #Create a function that takes a string and returns the word count. The string will be a sentence. #Examples #count_words("Just an example here move along") ➞ 6 #count_words("This is a test") ➞ 4 #count_words("What an easy task, right") ➞ 5 def count_words(txt): t = txt.split() return len(t) prin...
f96d35fd8ba47fc92f17627291bde8a896d72f02
ravalrupalj/BrainTeasers
/Edabit/Classes_for_Fetching.py
570
3.890625
4
def check(d1, d2, k): d1= { "sky": "temple", "horde": "orcs", "people": 12, "story": "fine", "sun": "bright" } d2 = { "people": 12, "sun": "star", "book": "bad" } if k in d1.keys() and k in d2.keys(): if d1[k]==d2[k]: return True elif d1[k]!=d2[k]: return 'Not the sa...
9975f7dc75b81bbbe7cfdcd701f2e09335a3ce54
ravalrupalj/BrainTeasers
/Edabit/Emptying_the_values.py
1,532
4.4375
4
#Emptying the Values #Given a list of values, return a list with each value replaced with the empty value of the same type. #More explicitly: #Replace integers (e.g. 1, 3), whose type is int, with 0 #Replace floats (e.g. 3.14, 2.17), whose type is float, with 0.0 #Replace strings (e.g. "abcde", "x"), whose type is st...
60a84a613c12d723ba5d141e657989f33930ab74
ravalrupalj/BrainTeasers
/Edabit/Powerful_Numbers.py
615
4.1875
4
#Powerful Numbers #Given a positive number x: #p = (p1, p2, …) # Set of *prime* factors of x #If the square of every item in p is also a factor of x, then x is said to be a powerful number. #Create a function that takes a number and returns True if it's powerful, False if it's not. def is_powerful(num): i=1 l=...
343894e3dc8546e4bfa0d70d8977f2e479b4a289
ravalrupalj/BrainTeasers
/Edabit/Wumbology.py
176
3.890625
4
#Create a function that flips M's to W's (all uppercase). #wumbo("I LOVE MAKING CHALLENGES") ➞ "I LOVE WAKING CHALLENGES" def wumbo(words): return words.replace('M','W')
bd0d3c9c1ac6c1923d86e7fe04013059fb85cbe5
ravalrupalj/BrainTeasers
/Edabit/Percentage_of_Box_filled.py
1,055
4.0625
4
#Percentage of Box Filled In #Create a function that calculates what percentage of the box is filled in. Give your answer as a string percentage rounded to the nearest integer. # Five elements out of sixteen spaces. #Only "o" will fill the box and also "o" will not be found outside of the box. #Don't focus on how much...
4eaf4aa432c28ae542c7f85144ac2ceb843f875e
ravalrupalj/BrainTeasers
/Edabit/Count_Letters_in_a_Word.py
789
4.09375
4
#Count Letters in a Word Search #Create a function that counts the number of times a particular letter shows up in the word search. #You will always be given a list with five sub-lists. def letter_counter(lst,letter): count=0 for i in lst: count=count+i.count(letter) return count print(letter_count...
4dd2faade46f718a07aeba94270ea71ff90b5996
ravalrupalj/BrainTeasers
/Edabit/Is_the_Number_Symmetrical.py
462
4.4375
4
#Create a function that takes a number as an argument and returns True or False depending on whether the number is symmetrical or not. A number is symmetrical when it is the same as its reverse. def is_symmetrical(num): t=str(num) return t==t[::-1] print(is_symmetrical(7227) ) #➞ True print(is_symmetrical(125...
885a0a3ce15dbf2504dd24ce14552a4e245b3790
ravalrupalj/BrainTeasers
/Edabit/Big_Countries.py
1,652
4.53125
5
#Big Countries #A country can be said as being big if it is: #Big in terms of population. #Big in terms of area. #Add to the Country class so that it contains the attribute is_big. Set it to True if either criterea are met: #Population is greater than 250 million. #Area is larger than 3 million square km. #Also, crea...
a22a66ffd651519956fc0f1ea0eb087a4146e8dd
ravalrupalj/BrainTeasers
/Edabit/Loves_Me_Loves_Me.py
1,034
4.25
4
#Loves Me, Loves Me Not... #"Loves me, loves me not" is a traditional game in which a person plucks off all the petals of a flower one by one, saying the phrase "Loves me" and "Loves me not" when determining whether the one that they love, loves them back. #Given a number of petals, return a string which repeats the p...
c12d6b85fe5baa9391cb20b87f11b903161fbf1b
ravalrupalj/BrainTeasers
/Edabit/Fix_the_Error.py
530
3.953125
4
#Remove all vowels def remove_vowels(st): l=['a','e','i','o','u'] ls=[] for i in st: if i not in l: ls.append(i) return ''.join(ls) def remove_vowels(string): vowels = "aeiou" for vowel in vowels: string=string.replace(vowel, "", ) return string print(remove_vow...
13b3a8a4d538ca1404902f5cc9d0d4cb5380f231
ravalrupalj/BrainTeasers
/Edabit/sum_of_even_numbers.py
698
4.1875
4
#Give Me the Even Numbers #Create a function that takes two parameters (start, stop), and returns the sum of all even numbers in the range. #sum_even_nums_in_range(10, 20) ➞ 90 # 10, 12, 14, 16, 18, 20 #sum_even_nums_in_range(51, 150) ➞ 5050 #sum_even_nums_in_range(63, 97) ➞ 1360 #Remember that the start and stop value...
7b59b568c79277f3cc78d138298452775574e14f
ravalrupalj/BrainTeasers
/Edabit/Combined.py
864
4.03125
4
#Combined Consecutive Sequence #Write a function that returns True if two lists, when combined, form a consecutive sequence. #The input lists will have unique values. #The input lists can be in any order. #A consecutive sequence is a sequence without any gaps in the integers, e.g. 1, 2, 3, 4, 5 is a consecutive seque...
7801a9735e3d51e4399ee8297d719d86eb44bc58
ravalrupalj/BrainTeasers
/Edabit/Recursion_Array_Sum.py
440
4.15625
4
#Recursion: Array Sum #Write a function that finds the sum of a list. Make your function recursive. #Return 0 for an empty list. #Check the Resources tab for info on recursion. def sum_recursively(lst): if len(lst)==0: return 0 return lst[0]+sum_recursively(lst[1:]) print(sum_recursively([1, 2, 3, 4])...
207c144e096524b8de5e6d9ca11ce5cb4969d8e1
ravalrupalj/BrainTeasers
/Edabit/Letters_Only.py
496
4.25
4
#Letters Only #Write a function that removes any non-letters from a string, returning a well-known film title. #See the Resources section for more information on Python string methods. def letters_only(string): l=[] for i in string: if i.isupper() or i.islower(): l.append(i) return ''.jo...
4fad5f1ab4362dbc1119d1f72a85d6c91abdfa8f
ravalrupalj/BrainTeasers
/Edabit/The_Fibonacci.py
368
4.3125
4
#The Fibonacci Number #Create a function that, given a number, returns the corresponding Fibonacci number. #The first number in the sequence starts at 1 (not 0). def fibonacci(num): a=0 b=1 for i in range(1,num+1): c=a+b a=b b=c return c print(fibonacci(3) ) #➞ 3 print(fibonac...
a04557bc33db1b02d40ccd9a7866e64eae63786c
ravalrupalj/BrainTeasers
/Edabit/Mini_Peaks.py
598
3.765625
4
#Mini Peaks #Write a function that returns all the elements in an array that are strictly greater than their adjacent left and right neighbors. def mini_peaks(lst): l=[] for i in range(1,len(lst)-1): if lst[i-1]<lst[i] and lst[i+1]<lst[i]: l.append(lst[i]) return l print(mini_peaks([4, 5...
5182829f043490134cb86a3962b07a791e7ae0cb
ravalrupalj/BrainTeasers
/Edabit/How_many.py
601
4.15625
4
#How Many "Prime Numbers" Are There? #Create a function that finds how many prime numbers there are, up to the given integer. def prime_numbers(num): count=0 i=1 while num: i=i+1 for j in range(2,i+1): if j>num: return count elif i%j==0 and i!=j: ...
f07bfd91788707f608a580b702f3905be2bf201b
ravalrupalj/BrainTeasers
/Edabit/One_Button_Messagin.py
650
4.28125
4
# One Button Messaging Device # Imagine a messaging device with only one button. For the letter A, you press the button one time, for E, you press it five times, for G, it's pressed seven times, etc, etc. # Write a function that takes a string (the message) and returns the total number of times the button is pressed. #...
d9acdd4825dfd641d4eac7dd92d15b428b0e07f0
ravalrupalj/BrainTeasers
/Edabit/Iterated_Square_Root.py
597
4.5
4
#Iterated Square Root #The iterated square root of a number is the number of times the square root function must be applied to bring the number strictly under 2. #Given an integer, return its iterated square root. Return "invalid" if it is negative. #Idea for iterated square root by Richard Spence. import math def i_sq...
edb6aaff5ead34484d01799aef3df830208b574c
ravalrupalj/BrainTeasers
/Edabit/Identical Characters.py
460
4.125
4
#Check if a String Contains only Identical Characters #Write a function that returns True if all characters in a string are identical and False otherwise. #Examples #is_identical("aaaaaa") ➞ True #is_identical("aabaaa") ➞ False #is_identical("ccccca") ➞ False #is_identical("kk") ➞ True def is_identical(s): return ...
da002bf4a8ece0c60f4103e5cbc92f641d27f573
ravalrupalj/BrainTeasers
/Edabit/Stand_in_line.py
674
4.21875
4
#Write a function that takes a list and a number as arguments. Add the number to the end of the list, then remove the first element of the list. The function should then return the updated list. #For an empty list input, return: "No list has been selected" def next_in_line(lst, num): if len(lst)>0: t=lst.po...
157488073da151c9907c967304ddd0f7933d22aa
ravalrupalj/BrainTeasers
/Edabit/Format_IV.py
813
3.53125
4
#Format IV: Escaping Curly Braces #For each challenge of this series you do not need to submit a function. Instead, you need to submit a template string that can formatted in order to get a certain outcome. #Write a template string according to the following example. Notice that the template will be formatted twice: #E...
b5255591c5a67f15767deee268a1972ca61497cd
ravalrupalj/BrainTeasers
/Edabit/Emphasise_the_Words.py
617
4.21875
4
#Emphasise the Words #The challenge is to recreate the functionality of the title() method into a function called emphasise(). The title() method capitalises the first letter of every word. #You won't run into any issues when dealing with numbers in strings. #Please don't use the title() method directly :( def emphasis...
75e00bb80cdd283eabe3f5b5733308c08ebde710
ravalrupalj/BrainTeasers
/Edabit/Who_Oldest.py
426
4.09375
4
#Given a dictionary containing the names and ages of a group of people, return the name of the oldest person. #All ages will be different. def oldest(dict): a=max(dict[i] for i in dict) for k,v in dict.items(): if a==v: return k print(oldest({ "Emma": 71, "Jack": 45, "Amy": 15, "Be...
6eceebf49b976ec2b757eee0c7907f2845c65afd
ravalrupalj/BrainTeasers
/Edabit/Is_String_Order.py
405
4.25
4
#Is the String in Order? #Create a function that takes a string and returns True or False, depending on whether the characters are in order or not. #You don't have to handle empty strings. def is_in_order(txt): t=''.join(sorted(txt)) return t==txt print(is_in_order("abc")) #➞ True print(is_in_order("edabit")) #...
1e445c240e84fdc0cc391791be49014670fc031c
ravalrupalj/BrainTeasers
/Edabit/Numbered_Alphabet.py
525
3.875
4
#Numbered Alphabet #Create a function that converts a string of letters to their respective number in the alphabet. #Make sure the numbers are spaced. #A B C D E F G H I J K L M N O P Q R S T U V W ... #0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ... def alph_num(txt): l='' for i in txt: ...
56bf743185fc87230c9cb8d0199232d393757809
ravalrupalj/BrainTeasers
/Edabit/Day 2.5.py
793
4.53125
5
#He tells you that if you multiply the height for the square of the radius and multiply the result for the mathematical constant π (Pi), you will obtain the total volume of the pizza. Implement a function that returns the volume of the pizza as a whole number, rounding it to the nearest integer (and rounding up for num...
d9d1a7dbd41fea7d00f7299ae6708fc46e21d42d
ravalrupalj/BrainTeasers
/Edabit/Day 4.4.py
510
4.46875
4
#Is It a Triangle? #Create a function that takes three numbers as arguments and returns True if it's a triangle and False if not. #is_triangle(2, 3, 4) ➞ True #is_triangle(3, 4, 5) ➞ True #is_triangle(4, 3, 8) ➞ False #Notes #a, b and, c are the side lengths of the triangles. #Test input will always be three positive n...
a055bcd166678d801d9f2467347d9dfcd0e49254
ravalrupalj/BrainTeasers
/Edabit/Count_and_Identify.py
832
4.25
4
#Count and Identify Data Types #Given a function that accepts unlimited arguments, check and count how many data types are in those arguments. Finally return the total in a list. #List order is: #[int, str, bool, list, tuple, dictionary] def count_datatypes(*args): lst=[type(i) for i in args] return [lst.count...
fde94a7ba52fa1663a992ac28467e42cda866a9b
ravalrupalj/BrainTeasers
/Edabit/Lexicorgraphically First_last.py
762
4.15625
4
#Lexicographically First and Last #Write a function that returns the lexicographically first and lexicographically last rearrangements of a string. Output the results in the following manner: #first_and_last(string) ➞ [first, last] #Lexicographically first: the permutation of the string that would appear first in the E...
5c503edd8d4241b5e674e0f88b5c0edbe0888235
ravalrupalj/BrainTeasers
/Edabit/Explosion_Intensity.py
1,312
4.3125
4
#Explosion Intensity #Given an number, return a string of the word "Boom", which varies in the following ways: #The string should include n number of "o"s, unless n is below 2 (in that case, return "boom"). #If n is evenly divisible by 2, add an exclamation mark to the end. #If n is evenly divisible by 5, return the s...
bc123a73adc60347bc2e8195581e6d556b27c329
ravalrupalj/BrainTeasers
/Edabit/Check_if_an_array.py
869
4.28125
4
#Check if an array is sorted and rotated #Given a list of distinct integers, create a function that checks if the list is sorted and rotated clockwise. If so, return "YES"; otherwise return "NO". def check(lst): posi = sorted(lst) for i in range(0,len(lst)-1): first=posi.pop(0) posi.append(firs...
a3b5f7ffe220bd211b6fde53c99b9bcb086dbf39
ravalrupalj/BrainTeasers
/Edabit/Reverse_the_odd.py
656
4.4375
4
#Reverse the Odd Length Words #Given a string, reverse all the words which have odd length. The even length words are not changed. def reverse_odd(string): new_lst=string.split() s='' for i in new_lst: if len(i)%2!=0: t=i[::-1] s=s+t+' ' else: s=s+i+' ' ...
9e340932b584ffa288e7a3cf066e5c93ed2c8a1b
ravalrupalj/BrainTeasers
/OOP/Inheritance Class.py
504
3.9375
4
#Innheritance-Super class and Sub class #Single Level Inheritance #Multi Level Inheritance #Mulitple INheritance class A: def feature1(self): print('Feature 1 working') def feature2(self): print('Feature 2 working') class B(): def feature3(self): print('Feature 3 working') def fe...