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 |
|---|---|---|---|---|---|---|
86973ee3bc1be500ebbf678c64b1d1f07333daef | drop-table-lol/Fartcraft | /Animations/Animation.py | 1,149 | 3.5 | 4 | """animation.py
contains different animations with timelines we wish to play, similar to sprites,
though, we're using sprites as still images rather than sprite sheets, hence this file."""
import pygame
from Displays import Display
import Sprites
class Animation:
def __init__(self, x,y, type, gridObj):
self.x = x... |
8b639fa0be4883c266bb27c4bc64d903bfbcfc91 | mtinet/microbit | /before/charger(green).py | 1,014 | 3.5625 | 4 | # 차저
# flash: green 점점 밝게, stop: red 점점밝게
import radio
from random import randint
from microbit import *
import neopixel
# Create the "flash" animation frames. Can you work out how it's done?
flash = [Image().invert()*(i/9) for i in range(9, -1, -1)]
# The radio won't work unless it's switched on.
radio.on()
np = neo... |
416f02c2863f52b48b7f7afcbb99cd29bd491ba1 | jain1dit/entity-extraction | /Atoms/Atom_from_number_to_number.py | 23,767 | 4.21875 | 4 | """
EXTRACT A PREDEFINED PATTERN FROM TEXT
Returnes a list of unique values that follows the passed regex pattern and found in the text.
In case where no etitites were extracted, an empty list is returned.
Parameters:
1. entity_name -> name of the entity to be parsed.
2. definite_extraction_regex -> regular e... |
6f9d936c0c46889fd07ca508aa030a41c918966d | K-Stumbaugh/GitProjects | /PythonAgain/rangeByTwos.py | 233 | 3.96875 | 4 | #range by 1
print('addition by 1')
for i in range(12,16):
print(i)
#range by twos
print('addition by 2')
for i in range (0, 11, 2):
print(i)
#range subtraction
print('subtraction')
for i in range(5, -1, -1):
print(i)
|
26f2d3651294e73420ff40ed603baf1ac2abb269 | Rohitjoshiii/bank1 | /read example.py | 439 | 4.21875 | 4 | # STEP1-OPEN THE FILE
file=open("abc.txt","r")
#STEP2-READ THE FILE
#result=file.read(2) # read(2) means ir reads teo characters only
#result=file.readline() #readline() it print one line only
#result=file.readlines() #readlines() print all lines into list
line=file.readlines() # for loop ... |
c16ef9027338bdacfcd075303ee5a84be17c03f4 | juannico007/laberinto-logica-proposicional | /maze.py | 5,362 | 3.734375 | 4 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import numpy as np
import random
#Crea un laberinto de dimensiones n * m conectado, con 2 casillas que nunca tendran un muro en ella. Recibe:
#Dimensiones del tablero, f = filas, c = columnas como enteros, tamaño por defecto 7x7
#Caisllas de inicio y final como tupla... |
7dd022b7ea2b91c640ff2e3a2d661faca179a22e | rscircus/advent_of_code_2019 | /06.py | 2,642 | 3.90625 | 4 | from collections import defaultdict
# The task today is
# input: map of local orbits
# things orbit each other except the CenterOfMass
# if BBB orbits AAA it is written like `AAA)BBB`
# to verify maps, orbit count checksums are used: the total no of direct orbits and indirect orbits
#
# direct orbits: an object O orb... |
6673a47fee3138ba14d20bc97b6a3674328a7a70 | IceIce1ce/Pacman-AI-Project-HCMUS | /setup_map.py | 6,772 | 3.578125 | 4 | from util import *
from setting import *
import pygame
from copy import deepcopy
class Map:
# init for map
def __init__(self, width, height):
self.width = width # width of map
self.height = height # height of map
self.InitMap = initGame()
loading_map = [] # create an empty list ... |
cefd70520471331df28cce805b8041f465f8d24a | Pasha-Ignatyuk/python_tasks | /task_5_7.py | 912 | 4.15625 | 4 | """Дана целочисленная квадратная матрица. Найти в каждой строке наибольший
элемент и поменять его местами с элементом главной диагонали.[02-4.2-ML22]"""
import random
n = 4
m = 4
matrix = [[random.randrange(0, 10) for y in range(m)] for x in range(n)]
print(matrix)
def print_matrix(matrix):
for i in range(len(mat... |
1b3f5a6ae3442857926e1f0eeb7594566769929e | Pasha-Ignatyuk/python_tasks | /converter.py | 3,744 | 4.09375 | 4 | while True:
enter = int(input('Введите 1 для выбора конвертера дюймов в сантиметры, 2 - для выбора конвертера сантиметров в дюймы,\n '
'3 - миль в километры, 4 - километров в мили, 5 - фунтов в килограммы, 6 - килограммов в фунты,\n '
'7 - унций в граммы, 8 - граммов в унции, 9 - галл... |
b1fb588e178f59630573ba9af3629810832f5978 | Pasha-Ignatyuk/python_tasks | /task_4_4.py | 410 | 3.9375 | 4 | lst = [1, 2, 3, 4, 5]
lst_2_1 = [] # для цикла с while
lst_2_2 = [] # для цикла с for
first_item = lst.pop(0)
length = len(lst)
temporary = 0
while length > 0:
item = lst[temporary]
lst_2_1.append(item)
temporary += 1
length -= 1
else:
lst_2_1.append(first_item)
print(lst_2_1)
for i in lst:
... |
c20fb5d6dbd82dbbc090f8c85612dcce1da98f41 | Pasha-Ignatyuk/python_tasks | /task_11_1.py | 5,927 | 4 | 4 | class Computer:
def __init__(self, brand, type, price):
self.__brand = brand
self.__type = type
self.__price = price
def set_brand(self, brand):
if len(brand) in range(1, 10):
self.__brand = brand
else:
print('Брэнд не определен')
def set_typ... |
f23c3ebe2bfdd14b6735cd455bfc136bae291bb0 | Pasha-Ignatyuk/python_tasks | /task_13_01/func.py | 669 | 3.875 | 4 | class Func:
def __init__(self, arg1, arg2, operator):
self.arg1 = arg1
self.arg2 = arg2
self.operator = operator
def process(self):
if self.operator == '+':
return self.add()
elif self.operator == '-':
return self.subtract()
elif self.oper... |
186a78291be415955402729980afcf4b0829cf8b | AK-1121/code_extraction | /python/python_21522.py | 108 | 3.6875 | 4 | # Count number of matches between two strings python
>>> sum(a==b for a, b in zip('bob', 'boa'))
2
|
664ee2fddd0a90da5d197063cb14d604f2a6f65b | AK-1121/code_extraction | /python/python_14803.py | 92 | 3.65625 | 4 | # Remove repeated item in list in python
d = ['a', 'man', 'and', 'a', 'woman']
list(set(d))
|
e0587e98a14e5a3abb63dcc2627c513d6358dd1d | AK-1121/code_extraction | /python/python_84.py | 166 | 4.15625 | 4 | # How do I reverse a list using recursion in Python?
mylist = [1, 2, 3, 4, 5]
backwards = lambda l: (backwards (l[1:]) + l[:1] if l else [])
print backwards (mylist)
|
3c9b4f1bec33cbfb0f33a7f4b04085c309e30401 | AK-1121/code_extraction | /python/python_18589.py | 204 | 3.5625 | 4 | # combine list of lists in python (similar to string.join but as a list comprehension?)
>>> lis = [['A',1,2],['B',3,4]]
>>> [', '.join(map(str, x)) for x in lis ]
['A, 1, 2', 'B, 3, 4']
|
cd82d5d786108a30e1d00ad8276247f92c35d253 | AK-1121/code_extraction | /python/python_16612.py | 206 | 3.59375 | 4 | # Create a word replacement dictionary from list of tuples
>>> word_dict = {'et': ['horse','dog'], 'ft': ['horses','dogs']}
>>> dict(word_dict.values())
{'horses': 'dogs', 'horse': 'dog'}
|
161eabeb2ea6587543ccbd302402462e7eaf0d66 | AK-1121/code_extraction | /python/python_26845.py | 155 | 3.734375 | 4 | # Unit conversion using Python
amount, unit = input('Enter amount with units: ').split()[:2]
converted_data = int(amount) * {'in': 2.54, 'cm': 0.39}[unit]
|
985e9ff7f03b3c670b006d4ac8470239c57c38f0 | AK-1121/code_extraction | /python/python_22004.py | 97 | 3.921875 | 4 | # Python regex matching 1 or 2 but not 3 of a character
matches = (1 <= s.count('-') <= 2)
|
159cba82e824d397baf00cb6ee566c6ee0da656b | AK-1121/code_extraction | /python/python_17125.py | 224 | 3.609375 | 4 | # How to get the values in split python?
>>> l = ['column1:abc,def', 'column2:hij,klm', 'column3:xyz,pqr']
>>> [item.split(":")[1].split(',') for item in l]
[['abc', 'def'], ['hij', 'klm'], ['xyz', 'pqr']]
|
0def15b25817edc28742c3564faad7cc0c568730 | AK-1121/code_extraction | /python/python_3728.py | 147 | 3.71875 | 4 | # Python's example for "iter" function gives me TypeError
with open("mydata.txt") as fp:
for line in iter(fp.readline, ''):
print line
|
d5ad4b6867f72609ca64432551487a678c807b2c | AK-1121/code_extraction | /python/python_13685.py | 151 | 3.875 | 4 | # Returning index of list with greatest value
def thing(list_):
temp = enumerate(max(x) - min(x) for x in list_)
return max(x[::-1] for x in temp)
|
d2fc09c1de840c70fa1b458934b55d987b4af08c | AK-1121/code_extraction | /python/python_14368.py | 183 | 3.734375 | 4 | # How to add clickable links to open a folder/file in output of a print statement? (Python desktop application)
print('<a href="http://www.example.com">example text</a>')
|
d10c73852b5753ff7adbcf450d8f760d9c45fd62 | AK-1121/code_extraction | /python/python_29140.py | 293 | 3.8125 | 4 | # How to get a value and its key from a dictionary
>>> d = {'0003': ['Mike', 'Restrepo', 'mtrepot', '87654321'], '0001': ['John', 'Jelenski', 'jelensohn', 'snf23jn4'], '0002': ['Clyde', 'Owen', 'clonew', 'dummy2015']}
>>> [k for k, v in d.items() if 'mtrepot' in v]
['0003']
|
f81d1b37817d00eba34b59a5e5efc9bef35dbb7e | AK-1121/code_extraction | /python/python_26620.py | 126 | 3.609375 | 4 | # Format a string with a space between every two digits
s = "534349511"
print ' '.join([s[i:i+2] for i in range(0,len(s),2)])
|
513d44b97f28b60667481bbd25bbc92f6439e2a7 | AK-1121/code_extraction | /python/python_379.py | 148 | 3.578125 | 4 | # python create slice object from string
slice(*[{True: lambda n: None, False: int}[x == ''](x) for x in (mystring.split(':') + ['', '', ''])[:3]])
|
cc6dc009a3c4c690fe92d36054e9455632222d2b | AK-1121/code_extraction | /python/python_26084.py | 160 | 3.5 | 4 | # How to default to the default argument in Python
kwargs = dict((k, getattr(self, k)) for k in ('c', 'd') if getattr(self, k))
print_something(a, b, **kwargs)
|
5c0d57b426ec49b9c376327b2aaa3394f8e8312c | AK-1121/code_extraction | /python/python_1795.py | 109 | 3.609375 | 4 | # Multiple value checks using 'in' operator (Python)
if any(s in line for s in ('string1', 'string2', ...)):
|
76c2d851e6a53874393a2a3f6c2e2c3c8a51e786 | AK-1121/code_extraction | /python/python_15413.py | 180 | 3.578125 | 4 | # How can I change name of arbitrary columns in pandas df using lambda function?
os_list = ['osxx', 'centos', 'windowsx']
df.rename(columns=lambda x: x+'x' if x in os_list else x)
|
f64650e0b9921c56f05721bde940299447e9329f | AK-1121/code_extraction | /python/python_11742.py | 157 | 3.796875 | 4 | # Sort entries of dictionary in decreasing order and print first n entries
print sorted(mydictionary.items(), key=operator.itemgetter(1), reverse=True)[:10]
|
ea2e2de0294b53d70c00f689d08b742824d9388b | AK-1121/code_extraction | /python/python_11632.py | 119 | 4.6875 | 5 | # Replacing specific words in a string (Python)
str = "What $noun$ is $verb$?"
print str.replace("$noun$", "the heck")
|
8cc11edbf4514684f0ccebeb30a0086a8925dce2 | AK-1121/code_extraction | /python/python_21649.py | 148 | 3.734375 | 4 | # How to use regular expressions to only capture a word by itself rather than in another word?
import re
print re.subn('Co$','',"Company & Co")
|
9b18c33f304505db454d8de39d5f161bf11c9d0a | AK-1121/code_extraction | /python/python_10731.py | 124 | 3.640625 | 4 | # Is there a way to check a number against all numbers in a list?
if any(n % x == 0 for x in mylist):
print "Not Prime"
|
172e6672d7988b20147ea16cd5d76ae1b10d9d46 | AK-1121/code_extraction | /python/python_27058.py | 217 | 3.75 | 4 | # How to use a 'for' loop to iterate nested-list index items in Python 2.7?
for i in range(1,len(nList)):
for distance in nList[i]:
outputLlist.append('{} metres, {} metres, {} seconds'.format(*distance))
|
822db626d13358d4c9ec052aa640bef672a6ca98 | AK-1121/code_extraction | /python/python_8674.py | 86 | 4 | 4 | # Print the concatenation of the digits of two numbers in Python
print(str(2)+str(1))
|
a82f237a5fe2dc5ea77f54c863243879eabd99df | AK-1121/code_extraction | /python/python_26683.py | 198 | 3.640625 | 4 | # python sort list of lists based on inner element AND ignore case
>>> sorted([[1, 'C'], [2, 'D'], [3, 'a'], [4, 'b']], key=lambda x: x[1].lower())
[[3, 'a'], [4, 'b'], [1, 'C'], [2, 'D']]
|
40ba81aa3c5f61275d9a869a51f33566433e71de | AK-1121/code_extraction | /python/python_26885.py | 121 | 3.53125 | 4 | # Python - "Joining" list of lists of different types
new_list=[''.join(str(y) for x in z for y in x) for z in my_list]
|
a241bad2e4d14e44775f10c7924b10fb4e1696a0 | AK-1121/code_extraction | /python/python_862.py | 125 | 3.578125 | 4 | # Python string interpolation using dictionary and strings
mystr = "path: %s curr: %s prev: %s" % (mydict[path], curr, prev)
|
7f07ababf1f59da566aeb8a9048c83bdd2d27e4e | AK-1121/code_extraction | /python/python_23678.py | 168 | 3.6875 | 4 | # replacing line in a document with Python
import fileinput
for line in fileinput.input(filename, inplace=True):
print(line.replace(string_to_replace, new_string))
|
0e62422a2e6de1ac67e68e712db81101c53f4ed2 | AK-1121/code_extraction | /python/python_7107.py | 99 | 3.625 | 4 | # multiple actions in list comprehension python
for i in list:
print('bla1')
print('bla2')
|
420c0e931a427be69461d7c2b09f90869ef9917c | AK-1121/code_extraction | /python/python_12455.py | 200 | 3.96875 | 4 | # Python 2.7 creating a multidimensional list
>>> y = [[[] for i in range(n)] for i in range(n)]
>>> print y
[[[], [], [], []], [[], [], [], []], [[], [], [], []], [[], [], [], []]]
|
ac980d809ac2346ffa42f0fa1e4aa713b53c1e70 | AK-1121/code_extraction | /python/python_26532.py | 90 | 3.671875 | 4 | # Python - Finding string frequencies of list of strings in text file
words=f.readlines()
|
091355dfbbf02ae6dc7f47c1f60ff5ab6d90c40c | AK-1121/code_extraction | /python/python_4596.py | 191 | 3.71875 | 4 | # How do I convert characters like ":" to ":" in python?
>>> import re
>>> re.sub("&#(\d+);",lambda x:unichr(int(x.group(1),10)),"&#58; or &#46;")
u': or .'
|
771dbeaa855367594e04ac9bb29435943595e86b | AK-1121/code_extraction | /python/python_24461.py | 249 | 3.96875 | 4 | # Sorting a list depending on every other element in python
ls = ["Milan", 6, 2, "Inter", 3, 2, "Juventus", 5, 2]
>>> sorted([ls[i:i+3] for i in range(0,len(ls),3)], key=lambda x:x[1])
[['Inter', 3, 2], ['Juventus', 5, 2], ['Milan', 6, 2]]
|
abfa14b3ebae20849cfceacd4447d364a673ca8d | AK-1121/code_extraction | /python/python_3435.py | 114 | 3.609375 | 4 | # Converting string to tuple and adding to tuple
x = "(1,2,3)"
t = tuple(int(v) for v in re.findall("[0-9]+", x))
|
15b7cd0bdbcfb5931a79b39e99bd4bbd95205303 | AK-1121/code_extraction | /python/python_19914.py | 128 | 3.578125 | 4 | # Recursive sequence $x_n = \sqrt{2}$, $x_{n+1} = \sqrt{2x_n}$
X = [sqrt(2)]
for i in range(1,10):
X.append(sqrt(2*X[i-1]))
|
85eccc15475416a821627aaf5f09451349d0459f | AK-1121/code_extraction | /python/python_15569.py | 94 | 3.546875 | 4 | # Create dictionary from list python
myDic = {}
for list in lists:
myDic[list[0]] = list[:]
|
0649e2f5883095155b37721144037fddae45754e | AK-1121/code_extraction | /python/python_24238.py | 189 | 3.9375 | 4 | # Python collections.Counter How to print element and number of counts
with open(output_file, 'w') as f:
for word, count in word_list:
f.write("{0}\t{1}\n".format(word, count))
|
81f5986603b0a969596fa8e984f3b992145fad86 | AK-1121/code_extraction | /python/python_9674.py | 123 | 3.5625 | 4 | # How does a Python genius iterate over a single value in a Python tuple?
[ x[2] for x in score.keys() if x[0:2] == (0,1)]
|
576197e58d7b315fc8d043a91dfdccabce925e94 | AK-1121/code_extraction | /python/python_9896.py | 101 | 4 | 4 | # Accessing the last element in the list in python
>>> myl = [1,2,3]
>>> myl[-1]
3
|
952f6ffbeb56a84f348d546a13a115cc0b4d3da0 | AK-1121/code_extraction | /python/python_13197.py | 88 | 3.625 | 4 | # accessing python 2D array
a = [[1, 2, 3], [2, 3, 4]]
result = zip(*a)[0]
print result
|
a15bad952e9b61639ce81901c7ac605ebf21e711 | AK-1121/code_extraction | /python/python_414.py | 215 | 3.578125 | 4 | # Is there a way to get all the directories but not files in a directory in Python?
def listfiles(directory):
return [f for f in os.listdir(directory)
if os.path.isdir(os.path.join(directory, f))]
|
27c4732134fab6705968554a043b9736a1b36775 | AK-1121/code_extraction | /python/python_27291.py | 110 | 3.53125 | 4 | # How to print out a numbered list in Python 3
for a, b in enumerate(blob, 1):
print '{} {}'.format(a, b)
|
2791403dd2286573878045df2b10709866fd2a6d | AK-1121/code_extraction | /python/python_10702.py | 123 | 3.8125 | 4 | # Python function for capping a string to a maximum length
def cap(s, l):
return s if len(s)<=l else s[0:l-3]+'...'
|
311d176550126ab0ab9f3ab8549392471267d3a4 | AK-1121/code_extraction | /python/python_27093.py | 144 | 3.5625 | 4 | # How to find the length of a leading sequence in a string?
>>> F = lambda x:len(x)-len(x.lstrip(' '))
>>> F(' ' * 5 + 'a')
5
|
7e12ac9f808acfa9da4170d8ca46ffc6929c5769 | AK-1121/code_extraction | /python/python_12696.py | 73 | 3.578125 | 4 | # recursion function in python
fibonacci(number-1) + fibonacci(number-2)
|
6154ce1ce57efce3293bf4dd7a3e515eae87d012 | AK-1121/code_extraction | /python/python_21497.py | 109 | 3.640625 | 4 | # re.sub (python) substitute part of the matched string
re.sub(r'<p>(?=[A-Z]{2,})','<i>',MyText)
|
448e128ebcf213152408882b6921ade7c297a2e8 | AK-1121/code_extraction | /python/python_8840.py | 108 | 3.53125 | 4 | # how to find the excel value from row, col names in python?
d = ws.cell(row = 4, column = 2)
print d.value
|
95814d2e7ce29e94e8d18d4e21226397cdb20017 | AK-1121/code_extraction | /python/python_6317.py | 81 | 4.09375 | 4 | # How to convert string to lowercase in Python?
s = "Kilometer"
print(s.lower())
|
d8245029fd64484f4893bd5692565eb1ffef007c | AK-1121/code_extraction | /python/python_7543.py | 155 | 4.09375 | 4 | # How to search strings with certain number of occurence using Regular Expression?
Str1 = '"HHHHLLLHHHHHLLLLL"'
if Str1.count("H") >= 8 : print "match"
|
5951c39dd4cdc3a7b1018e8c43da7dc3dfd42a75 | AK-1121/code_extraction | /python/python_21301.py | 111 | 3.703125 | 4 | # Python: For loop in a for loop?
for d in students:
print d["name"],d["homework"],d["quizzes"],d["tests"]
|
db3c248cd270dad58a6386c4c9b6dc67e6ae4fab | AK-1121/code_extraction | /python/python_20317.py | 208 | 4.1875 | 4 | # Why mutable not working when expression is changed in python ?
y += [1,3] # Means append to y list [1,3], object stays same
y = y+[1,3] # Means create new list equals y + [1,3] and write link to it in y
|
20f6d2739125548325648dd8194e52dfbaa62821 | AK-1121/code_extraction | /python/python_24743.py | 240 | 3.875 | 4 | # Comparing Lists and Printing the Common
things = set(['Apple', 'Orange', 'Cherry','banana','dog','door','Chair'])
otherThings = set(['Apple', 'Orange','TV' ,'Cherry','banana','Cat','Pen','Computer','Book'])
print things & otherThings
|
cac07e3a272b7c9a27bde3f4a7c1afa19d039d21 | AK-1121/code_extraction | /python/python_14221.py | 106 | 3.75 | 4 | # Searching List of Tuples by nth element in Python
[t for t in list_of_tuples if t[1] == n or t[2] == n]
|
84285c6d355abb457b69a48fc62b23ff774678a6 | AK-1121/code_extraction | /python/python_24729.py | 170 | 3.75 | 4 | # Pandas framework: determining the count of a column data
counter = df["ItemID"].value_counts() #df is your dataframe
print counter[1] #prints how many times 1 occurred
|
4c805d46e5a5a1d541516b95e492076d126d632d | AK-1121/code_extraction | /python/python_13293.py | 149 | 3.59375 | 4 | # Format string with all elements of a list
>>> statement = "%s you are so %s at %s" % tuple(words)
'John you are so nice at skateboarding'
|
267919fe7bb7c9137a2d5fadb9c5125857421c7f | AK-1121/code_extraction | /python/python_3817.py | 106 | 3.640625 | 4 | # Sort list of strings by integer suffix in python
sorted(the_list, key = lambda x: int(x.split("_")[1]))
|
6c394abfea8781eae288b12287fc75099dcff03f | AK-1121/code_extraction | /python/python_3087.py | 200 | 3.578125 | 4 | # Image bit manipulation in Python
r, g, b = im.split() # split the image into separate color planes
im = Image.merge("RGB", (g, g, g)) # merge them back, using the green plane for each
|
7275c985231bb504bdb85d4cb8f88c8369bee1b3 | AK-1121/code_extraction | /python/python_9255.py | 166 | 3.546875 | 4 | # Python Regular Expressions: Capture lookahead value (capturing text without consuming it)
re.findall("([%]+)([^%]+)(?=([%]+))".replace("%", "".join(VOWELS)), word)
|
ac89ff06bf3ce8e6d71819481091160983ebfd3b | AK-1121/code_extraction | /python/python_8529.py | 242 | 3.75 | 4 | # How do I format text from a file in Python?
def print_table(lines, col_num, col_width):
for line_ix in range(0, len(lines), col_num):
print ' -- '.join([line.strip().ljust(col_width) for line in lines[line_ix:line_ix+col_num]])
|
af072c303c1672dbe0dda1994fb6bdaf67a6c1ff | AK-1121/code_extraction | /python/python_234.py | 123 | 3.515625 | 4 | # Deleting multiple elements from a list
indices = 0, 2
somelist = [i for j, i in enumerate(somelist) if j not in indices]
|
ed27b44628db1b53914555d9e875c6d064d18e52 | AK-1121/code_extraction | /python/python_5693.py | 210 | 3.609375 | 4 | # Regex Python - Find every keyword instance, extract keyword and proceeding characters
Input text: DODOD987654321
First match: DODOD987654321
Second match: DOD987654321 # Not found by re.finditer()
|
d8edfb9fbebf0510af3aa451c01403797a710e2b | AK-1121/code_extraction | /python/python_15459.py | 118 | 3.609375 | 4 | # Python - Most effective way to implement two's complement?
x=int(a,2)
num_bits = 10
print x - (1 << num_bits)
|
2539312375a1568d8046330ed9660e0c7eb2d79e | AK-1121/code_extraction | /python/python_6924.py | 130 | 3.625 | 4 | # Query Python dictionary to get value from tuple
>>> D = {"Key1": (1,2,3), "Key2": (4,5,6)}
>>> D["Key2"][2]
6
|
4afc089e167a801c419df83e6ca748a2e78e4156 | AK-1121/code_extraction | /python/python_15965.py | 219 | 3.96875 | 4 | # Can I return a list of ALL min tuples, using Python's Min function?
listo = [('a','1'),('b','0'),('c','2'),('d','0')]
minValue = min(listo, key=lambda x: x[1])[1]
minValueList = [x for x in listo if x[1] == minValue]
|
fb640fc148d60aa1a1f66f13a0052f77c1542b01 | AK-1121/code_extraction | /python/python_78.py | 110 | 4.03125 | 4 | # How to check if a string in Python is in ASCII?
def is_ascii(s):
return all(ord(c) < 128 for c in s)
|
609e93c9cdbcbf5833e1e740f6e4b6186107e21e | AK-1121/code_extraction | /python/python_9240.py | 137 | 3.59375 | 4 | # Smallest way to expand a list by n
>>> l = [1,2,3,4]
>>> [it for it in l for _ in range(2)]
[1, 1, 2, 2, 3, 3, 4, 4]
|
1e2e00ebac409aae87e026b011e410511b3435b8 | AK-1121/code_extraction | /python/python_14135.py | 129 | 3.65625 | 4 | # invert a tuple array python
array = [(126,150),(124,154),(123,145),(123,149)]
inversed = [(item[1],item[0]) for item in array]
|
a0c0614800285c1c323ca4fd807b5aedb3f139e8 | AK-1121/code_extraction | /python/python_15393.py | 198 | 3.59375 | 4 | # Python: Modified sorting order for a list
>>> items = ['24/2', '24/3', '25/2', '6']
>>> sorted(items, key=lambda s: [int(n) for n in s.split('/')])
['6', '24/2', '24/3', '25/2']
|
a29ff60c305f8d9bf7c7e537fc2cffed934cedd3 | AK-1121/code_extraction | /python/python_1715.py | 97 | 3.640625 | 4 | # How to input an integer tuple from user?
tuple(int(x.strip()) for x in raw_input().split(','))
|
3db6a0aea7728ac61e77fbc25756adf1e467d3ea | AK-1121/code_extraction | /python/python_22304.py | 269 | 3.515625 | 4 | # NumPy convert 8-bit to 16/32-bit image
i = cv2.imread(imgNameIn, cv2.CV_LOAD_IMAGE_COLOR) # Need to be sure to have a 8-bit input
img = np.array(i, dtype=np.uint16) # This line only change the type, not values
img *= 256 # Now we get the good values in 16 bit format
|
a0d03d175e5732aa674a3369aeae2200a593d006 | AK-1121/code_extraction | /python/python_24297.py | 160 | 3.984375 | 4 | # Iterating through the same key in different items python dictionary
for key1 in dict:
for key2 in dict[key1]:
dict[key1][key2]['time'] = 'newTime'
|
442a1825bbe5b1e7d9a2462c90d2e6514ad5d807 | AK-1121/code_extraction | /python/python_11438.py | 173 | 3.5625 | 4 | # How can I split a string in Python?
my_str="123456781234567812345678"
splits=[my_str[x:x+8] for x in range(0,len(my_str),8)]
//splits = ["12345678","12345678","12345678"]
|
2f06e68c18f3678f38e13b15f4cc33cd6b61b45a | AK-1121/code_extraction | /python/python_15357.py | 159 | 3.625 | 4 | # Convert a number enclosed in parentheses (string) to a negative integer (or float) using Python?
my_str = "(4,301)"
num = -int(my_str.translate(None,"(),"))
|
21435912ae2bb268ec90d4f5e903a4a7428cad28 | AK-1121/code_extraction | /python/python_18681.py | 90 | 3.859375 | 4 | # Sum up all the integers in range()
res = sum(x for x in range(100, 2001) if x % 3 == 0)
|
e16d5d2398c8fb9089a4191971767561bb71f827 | AK-1121/code_extraction | /python/python_4752.py | 143 | 3.609375 | 4 | # Writing data from python list?
assert len(A) == len(B) == len(C)
for a, b, c in zip(A, B, C):
print a, b, c # replace with file write
|
576cc6138dd0ca91d403479303a71da31dc00dd9 | AK-1121/code_extraction | /python/python_17002.py | 121 | 3.53125 | 4 | # Checking for multiple strings in python in a dictionary
location = location + sum(mot[x][1] for x in mot if x in str2)
|
040c8f196de94e2c59d9e9e73bf7fdf4616c9504 | AK-1121/code_extraction | /python/python_16918.py | 103 | 3.515625 | 4 | # Simplifying Python string regex/pattern matching
MyString = MyString.strip(", ").replace(", , ", "")
|
3225e1591c18b6a5f05b1ddbb4fd4da42bcd628a | AK-1121/code_extraction | /python/python_18057.py | 179 | 3.75 | 4 | # Python: "Distributing" strings from two lists into one list
>>> print(list(itertools.product(['a', 'b'], ['c', 'd'])))
[('a', 'c'), ('a', 'd'), ('b', 'c'), ('b', 'd')]
|
a6075e5910e620751a33078e54e2f556c06bc2fe | AK-1121/code_extraction | /python/python_3697.py | 192 | 3.828125 | 4 | # Python and character normalization
How to detect if the values in array are in a certain range and return a binary array in Python?
Y=X[0,:]+X[1,:]
D = ((1<Y) & (Y<2)).astype(int)
|
768c0b4ff8462e908f1a2a6187e5eaa2d6e94423 | AK-1121/code_extraction | /python/python_7357.py | 164 | 3.625 | 4 | # How to unpack 6 bytes as single integer using struct in Python
def unpack48(x):
x1, x2, x3 = struct.unpack('<HHI', x)
return x1, x2 | (x3 << 16)
|
529d5340d46bba259674e33f25b6c1adedc291ea | AK-1121/code_extraction | /python/python_28175.py | 252 | 3.75 | 4 | # Using .find to search a string inside a list
>>> list_of_strings = ['Hello!, my name is Carl', 'Hello!, my name is Steve', 'Hello!, my name is Betty', 'My Name is Josh']
>>> [s.find('Hello!') for s in list_of_strings]
[0, 0, 0, -1]
|
15839f452377dcc38908ac3dc51490c62f216c94 | AK-1121/code_extraction | /python/python_20396.py | 239 | 4.09375 | 4 | # replaces multiple occurances of a character (except for first and last) in a python string
str1 = '$2a$10$.XfjKl/,abcd, 1, ##, s, for free,2-3-4'
parts = str1.split(',')
str2 = '{},{},{}'.format(parts[0],'_'.join(parts[1:-1]),parts[-1])
|
09cf1dbfa8916742afabfe3bfe8a12cc69d39779 | AK-1121/code_extraction | /python/python_5432.py | 138 | 3.84375 | 4 | # Referencing the ith element of each list in a 2d list
i = 1
data = [[1,10],[2,20],[3,30]]
result = [d[i] for d in data] # [10, 20, 30]
|
5b68be99f1426969b5ec0ba86e1a14c7fe530d15 | AK-1121/code_extraction | /python/python_1113.py | 186 | 4.09375 | 4 | # Is there a way to split a string by every nth separator in Python?
span = 2
words = "this-is-a-string".split("-")
print ["-".join(words[i:i+span]) for i in range(0, len(words), span)]
|
92874a6a6da9162b9a862680fc9d652523167571 | AK-1121/code_extraction | /python/python_23762.py | 130 | 4.03125 | 4 | # How to print the date and time in Python from string?
>> dt = time.strftime('%d-%b-%Y', dt)
>> print dt
11-Aug-2014
|
c193ac400d6c591bb3268f3b7e32d52c0d9b1475 | AK-1121/code_extraction | /python/python_7056.py | 98 | 3.5 | 4 | # Reading Space separated input in python
the_string = raw_input()
name, age = the_string.split()
|
d7308cbef556b8cae091b39c756e06274fd842ec | AK-1121/code_extraction | /python/python_27038.py | 92 | 3.8125 | 4 | # How to add commas to digits in Python 3?
print("Your income tax is ${:,}".format(income))
|
2a92daaf819f922f79b7c5fd2729533a6ea3fc50 | AK-1121/code_extraction | /python/python_79.py | 153 | 4 | 4 | # I'm looking for a pythonic way to insert a space before capital letters
>>> re.sub(r"(\w)([A-Z])", r"\1 \2", "WordWordWord")
'Word Word Word'
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.