Datasets:
text stringlengths 41 3.71k | ntok int64 40 1.02k | style stringclasses 3
values | name stringlengths 1 252 | hash stringlengths 24 24 | model stringclasses 2
values |
|---|---|---|---|---|---|
def partition_integers(values: list[int]) -> tuple[int]:
"""Partition a list of integers into three groups based on a central value:
values smaller than the central value, values equal to the central value, and values
larger than the central value.
"""
median_index: int = int(len(values) / 2)
me... | 626 | mix | partition_integers.py | cb93cf64124968748a9d7b63 | Qwen/Qwen2.5-Coder-7B |
def partition_integers(numbers: list[int]) -> list[list[int]]:
"""Partition a list of integers into sublists based on whether they are even or
odd.
"""
even: list[int] = []
odd: list[int] = []
for num in numbers:
if num % 2 == 0:
even.append(num)
else:
odd... | 116 | mix | partition_integers.py | 9fb64dc62973ceec851fa50f | Qwen/Qwen2.5-Coder-7B |
def partition_integers(numbers: list[int]) -> list[int]:
"""Separate an array of integers into even and odd sublists and return them as a
two-element list.
"""
even: list[int] = []
odd: list[int] = []
for number in numbers:
if number % 2 == 0:
even.append(number)
else... | 120 | mix | partition_integers.py | b0def072f060bb93d5395ac9 | Qwen/Qwen2.5-Coder-7B |
def partition_integers(numbers: list[int]) -> tuple[list[int], list[int]]:
"""Partition a list of integers into a list of even and a list of odd numbers,
maintaining their original order. Return a tuple containing the two partitioned
lists in the order of (even, odd).
"""
evens: list[int] = []
o... | 162 | mix | partition_integers.py | cdfd16bdfe6385f8a8a7967d | Qwen/Qwen2.5-Coder-7B |
def partition_integers(nums: list[int], p: int, lower_bound: int = 0, upper_bound: int = 0) -> list[int]:
"""Partition a list of integers into those above and below a given threshold."""
if lower_bound == upper_bound == 0:
lower_bound = min(nums)
upper_bound = max(nums)
result: list[int] = ... | 143 | mix | partition_integers.py | e3e4a38cc8e74f0cba328e39 | Qwen/Qwen2.5-Coder-7B |
def partition_integers(numbers: list[int]) -> list[list[int]]:
"""Partition a list of integers into two sublists such that the elements of the
first sublist form an arithmetic sequence and the elements of the second sublist
are not part of any arithmetic sequence, excluding zero.
"""
arithmetic_subl... | 304 | mix | partition_integers.py | 029c5c54f0bc57ca9566d433 | Qwen/Qwen2.5-Coder-7B |
def partition_integers(numbers: list[int]) -> tuple[list[int], list[int]]:
"""Partition a list of integers into two groups: even and odd numbers. Returns a
tuple containing two lists, with the first list holding even numbers and the second
containing odd numbers.
"""
even_numbers: list[int] = []
... | 158 | mix | partition_integers.py | 5669248717f868b6926c21fe | Qwen/Qwen2.5-Coder-7B |
def partition_integers(numbers: list[int]) -> list[int]:
"""Partition a list of integers into two categories, positive and non-positive, and
return a sorted list containing these partitions.
"""
partitioned: list[int] = [n for n in numbers if n > 0] + \
[n for n in numbers if n <= 0]
return ... | 118 | mix | partition_integers.py | 2d63495c514f3693295df269 | Qwen/Qwen2.5-Coder-7B |
def partition_integers(numbers: list[int], target: int) -> list[list[int]]:
"""Partitions a list of integers into sublists of contiguous elements, where the sum
of each sublist is less than or equal to the specified target value.
"""
partitions = []
current_partition = []
for number in numbers:... | 170 | mix | partition_integers.py | 003cc9397650c3c0528f3ffc | Qwen/Qwen2.5-Coder-7B |
def partition_integers(numbers: list[int]) -> list[list[int]]:
"""Partition a list of integers into separate lists based on even and odd values."""
even_numbers: list[int] = []
odd_numbers: list[int] = []
for number in numbers:
if number % 2 == 0:
even_numbers.append(number)
... | 123 | mix | partition_integers.py | 2442e71cb3959508633e1681 | Qwen/Qwen2.5-Coder-7B |
def partition_integers(numbers: list[int]) -> dict[str, int]:
"""Partition a list of integers into a dictionary with odd and even key names, and
values representing the counts of odd and even numbers in the list.
"""
result = {'odd': 0, 'even': 0}
for num in numbers:
if num % 2 == 0:
... | 129 | mix | partition_integers.py | 9b72420a73a90e5f5726836f | Qwen/Qwen2.5-Coder-7B |
def partition_integers(nums: list[int], pivot: int) -> None:
"""Sort a list of integers in place by partitioning elements around a pivot value.
"""
start: int = 0
end: int = len(nums) - 1
idx: int = 0
while idx <= end:
if nums[idx] > pivot:
nums[idx], nums[end] = nums[end], n... | 191 | mix | partition_integers.py | f106ccab29c2c20321397afd | Qwen/Qwen2.5-Coder-7B |
def increment_values(values: list[int]) -> list[int]:
"""Increment each integer in a list by one."""
return [value + 1 for value in values]
def increment_value(value: int) -> int:
"""Increment an integer by one."""
return value + 1
def increment_int(values: list[int], value: int) -> list[int]:
"... | 228 | mix | partition_integers.py | 9afb9a6e4549603187e8d58d | Qwen/Qwen2.5-Coder-7B |
def partition_integers(numbers: list[int]) -> list[int]:
"""Partition a list of integers into a single list where odd numbers appear
first, followed by even numbers.
"""
odd_numbers: list[int] = []
even_numbers: list[int] = []
for num in numbers:
if num % 2 == 0:
even_numbers... | 132 | mix | partition_integers.py | 14f5f41c9c174febf50f00d0 | Qwen/Qwen2.5-Coder-7B |
class Solution:
def majorityElement(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
import random
if not nums:
return None
random.shuffle(nums)
for i in range(len(nums)):
if nums.count(nums[i]) > len(nums) / 2:
... | 100 | pe | comparison.py | 3d3a25abba20c7131cebd325 | Qwen/Qwen2.5-Coder-7B |
# -*- coding: utf-8 -*-
class Solution(object):
def repeatedSubstringPattern(self, s):
"""
:type s: str
:rtype: bool
"""
str1 = ""
for i in range(len(s) // 2):
str1 += s[i]
if str1 * (len(s) // len(str1)) == s and len(str1) < len(s):
... | 184 | pe | comparison.py | 60658701db89b3328ece38e8 | Qwen/Qwen2.5-Coder-7B |
class fibGenerator():
def __init__(self):
self.curr = 0
self.next = 1
def __next__(self):
fib = self.curr
self.curr, self.next = self.next, self.curr + self.next
return fib
def __iter__(self):
return self
if __name__ == "__main__":
fib_iter = fibGenerator... | 151 | pe | comparison.py | 1f77d4e25cd2a81ec2da3f73 | Qwen/Qwen2.5-Coder-7B |
class car:
def __init__(self,model,color):
self.model=model
self.color=color
car1=car('X','yellow')
car2=car('X','blue')
print("Is car1.color equal car2.color ? ",car1.color == car2.color)
print("Is car1.color different car2.color ? ",car1.color != car2.color)
| 142 | pe | comparison.py | 3db4143e8b4985aca3dd63fa | Qwen/Qwen2.5-Coder-7B |
class Animal:
def __init__(self,species, age):
self.species = species
self.age = age
self.energy_level = 0
def feed(self):
self.energy_level += 1
print("yum")
def play(self):
if self.energy_level > 0:
self.energy_level -= 1
pr... | 228 | pe | comparison.py | ebbf2281cfae0ce0b39118a3 | Qwen/Qwen2.5-Coder-7B |
class Node:
def __init__(self,item):
self.left=None
self.right=None
self.val=item
def preorder(root):
print(root.val,end=" ")
preorder(root.left)
preorder(root.right)
root = Node(1)
root.left=Node(2)
root.right=Node(3)
root.left.left=Node(4)
root.left.right=Node(5)
preorder(ro... | 116 | pe | comparison.py | 4dd7a5e115ff667275179aec | Qwen/Qwen2.5-Coder-7B |
number = int(input("Enter a Number: "))
if number < 0:
print("Factorial does not exist for negative numbers")
elif number == 0:
print("The factorial of 0 is 1")
else:
fact = 1
for i in range(1,number + 1):
fact = fact*i
print("The factorial of",number,"is",fact) | 118 | pe | comparison.py | 6e1b64bfaebacc7817b6ab9d | Qwen/Qwen2.5-Coder-7B |
class Demo:
def __init__(self, text):
self.text = text
def __gt__(self, other):
return self.text > other.text
obj1 = Demo("Today")
obj2 = Demo("Tomorrow")
print(obj1 > obj2) | 80 | pe | comparison.py | c1d916e440fefb909519cacd | Qwen/Qwen2.5-Coder-7B |
#A solution to version 1 of The Greeters Kata
# Define a singleton that provides methods to return the welcome greeting and the goodbye greeting.
class Greeters:
def greetHello(name):
return 'Hello %s' % (name)
def greetGoodbye(name):
return 'Goodbye %s' % (name)
# Define a controlle... | 509 | pe | pattern3.py | d3add93a4b694237d55543ad | Qwen/Qwen2.5-Coder-7B |
number = int(input('Input integer number:'))
summand = number//100+number%100//10+number%10
print(summand) | 44 | pe | pattern3.py | f3d136259e16a82f6c2c783f | Qwen/Qwen2.5-Coder-7B |
# Recursive function for Calculating nth Fibonacci number
# Precondition : n >= 1
# Postcondition: fib(n) = fib(n-1)+fib(n-2) for n>1
# = 1 for n==1
def fib(n):
if (n==1):
return 1
elif(n==2):
return 1
else:
return fib(n-1) + fib(n-2)
# if v... | 228 | pe | pattern3.py | 83c1c6f2557f55ba3a9e1ea9 | Qwen/Qwen2.5-Coder-7B |
# pattern 3
length = int(input("Input length "))
widht = int(input("Input widht "))
color = input("Input color ")
text1 = input("Input text ")
for i in range(length):
for j in range(widht):
if(i == 0 or i == length-1):
print(color,end="")
elif(j == 0 or j == widht-1):
print(... | 136 | pe | pattern3.py | d6bca5001cd3e819b06304c5 | Qwen/Qwen2.5-Coder-7B |
#!/bin/python3
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 2 23:51:56 2017
@author: Alex
Write a program that prints a date in 2 different formats. First of all,
the full date consisting of day, month, and year; next just the year only.
Use two separate date variables. These variables should be printed using the
... | 321 | pe | pattern3.py | 9f221cac9a3310d68843d271 | Qwen/Qwen2.5-Coder-7B |
for i in range(20,121):
if i%2 == 0 :
print(i, end=' ')
for i in range(20,121):
print(i, end=' ')
i+=2 | 51 | pe | pattern3.py | 0c1c47853cb34096801812ae | Qwen/Qwen2.5-Coder-7B |
import re
filename=input('Enter file name:')
f=open(filename,'r')
lines=f.readlines()
word_num=0
char_num=0
for line in lines:
word_num += len(line.split())
char_num += len(line)
print('line:',len(lines),'words:',word_num,'characters:',char_num) | 90 | pe | pattern3.py | 2625afcc6435099c0b2a7fc6 | Qwen/Qwen2.5-Coder-7B |
"""
SIMPLE DECORATOR FACTORY EXAMPLE
GOAL:
Create a decorator factory to implement "wider" decorators such as 'logging'
Based on the decorator factory shown in class (as 'shouting')
USAGE:
Create a logging decorator to log only when decorator arguments
dictate so. Decorator arguments are passed wh... | 544 | pe | pattern3.py | 1004f38adf8b35806970c9a5 | Qwen/Qwen2.5-Coder-7B |
import math
n = int(input("Input any number:"))
sum = 0
if (n <= 0) :
print("Please input a positive number")
n = int(input("Input any number:"))
while(n > 0):
sum += math.factorial(n % 10)
n //= 10
print(sum) | 91 | pe | pattern3.py | 8e7f30c8be6347925f26c7e6 | Qwen/Qwen2.5-Coder-7B |
#!/usr/bin/env python3
"""
This script returns the smallest of 3 numbers a,b,c
This script works on python3 interpreter only
Ref: https://docs.python.org/3/library/functions.html?highlight=max#max
"""
def minimum(a, b, c):
"""
:param a: int - value for parameter
:param b: int - value for par... | 254 | pe | pattern3.py | a0e853b4be51f0dcdedd85ec | Qwen/Qwen2.5-Coder-7B |
#!flask/bin/python
'''
Test program to make sure the logic to extract the result from the MonteCarlo works properly
'''
import sys
import re
# function for getting valid user age
def getAge():
try:
age = int(input('Enter your age: '))
while (age < 0):
print('Age cannot be negative')
... | 408 | pe | pattern3.py | fc09d2cee309abd487fb5947 | Qwen/Qwen2.5-Coder-7B |
#EXAMEN FINAL , TARDE 10/7/21
import string
import random
def random_roler():
random_letters = []
for _ in range(4):
random_letters.append(random.choice(string.ascii_letters))
random_int = random.choice(range(9))
random_string = "".join(random_letters) + str(random_int)
return random_stri... | 259 | pe | question1.py | 81e8b0e10de5d338fc6de62e | Qwen/Qwen2.5-Coder-7B |
def subset_sum(numbers, target, partial=[]):
s = sum(partial)
# check if the partial sum is equals to target
if s == target:
print("sum(%s)=%s" % (partial, target))
if s >= target:
return # if we reach the number why bother to continue
for i in range(len(numbers)):
n = num... | 169 | pe | question1.py | ad1d9399ce002425655473aa | Qwen/Qwen2.5-Coder-7B |
#ejercicio 1
try:
g=float(input("peso="))
k=int(input("tipo="))
except TypeError:
print("false")
def calculate_distance(r):
r=((2**2)+(r**2))**0.5
return r
def calculate_weight(gra,kg):
we=kg*gra
return we
def calculat_gravity(distancia):
gravity=(6.674*(10**(-11)))*5.973*(10**24)/dist... | 205 | pe | question1.py | a10fce0e5ff13d6ab40ed242 | Qwen/Qwen2.5-Coder-7B |
import random
"""
Example of Merge Sort
(6 / 7 / 2021)
"""
numbers = random.sample(range(1, 99), 4)
print("the array before sorting is ", numbers)
def MergeSort(array):
if len(array) > 1:
mid = len(array) // 2
# copy the first half of the array and merge them into their half arrays
leftHa... | 599 | pe | question1.py | e76ed7710babb33ae885b3b2 | Qwen/Qwen2.5-Coder-7B |
# brute force method of this algorithm has a time complexity of O(n ** 2) which can be solved with the DP algorithm
# this DP algorithm solves the problem in O(n) time complexity and in space complexity of O(1)
# note that the idea is to find the sum of the row numbers times the number of numbers in that row and
# also... | 401 | pe | question1.py | 1c7328a71ea980865298862c | Qwen/Qwen2.5-Coder-7B |
import random
import math
firstNum1, firstNum2 = random.randint(0,9), random.randint(0,9)
secondNum1, secondNum2 = random.randint(0,9), random.randint(0,9)
#compute what the user will have to guess
print(firstNum1,"+",firstNum2,"+",secondNum1,"+",secondNum2)
number = input("please enter your answer:")
print(firstNum1... | 207 | pe | question1.py | ddbb3a4e7d78206aba498b38 | Qwen/Qwen2.5-Coder-7B |
import random
secret = random.randint(1,100)
guess = int(input("ingrese el numero:"))
lives = int(input("ingrese sus vidas: "))
if lives>=3:
print("aviso recuerde que solo se le permite perder 3 veces")
while (guess != secret) and (lives>0):
print("Intenta de nuevo.")
guess=int(input("ingrese el numero:"))
... | 224 | pe | question1.py | 068203acd422d51e1d5decf2 | Qwen/Qwen2.5-Coder-7B |
def place(self,x,y):
y=y-1 #because it starts with zero
x=x-1 #because it starts with zero
pos=x+3*y
#print(pos)
self.lista[pos]=self.pieces[self.pieces_pos]
self.pieces_pos+=1
#print(self.pieces[self.pieces_pos-1])
self.pos=pos
def down(self):
... | 427 | pe | question1.py | 42f7737b6b2535147f740687 | Qwen/Qwen2.5-Coder-7B |
class input_info():
def __init__(self):
pass
def input_name(self, name):
self.name = name
def input_nato(self, nato):
self.nato = nato
def input_freq(self, freq):
self.freq = freq
def input_band(self, band):
self.band = band
class fleet():
def __init__(self):
self.target = None
self.freq = Non... | 253 | pe | question1.py | 458fcabeba896c114c0d3caf | Qwen/Qwen2.5-Coder-7B |
print('Szkolimy się')
name='Przemek'
print(name[0])
print(name[-1])
print(name[1:4])
height=170
temperature=27.4
print(name, height, temperature)
str1= "Hello there i'm your brother"
print(str1.upper())
str1= str1.upper()
print(str1.lower()) | 109 | pe | tuple.py | fd25b0e816c8b2aeacaa5f5f | Qwen/Qwen2.5-Coder-7B |
class Number:
def __init__(self):
self.number = 0
class Number2:
def __init__(self, number=0):
self.number = number
if __name__ == '__main__':
number = Number()
number.number = 2
number2 = Number2()
number2.number = number.number
number.number = 3
print(number.number... | 110 | pe | tuple.py | f0ce711c7bf6ad5959dbb1ae | Qwen/Qwen2.5-Coder-7B |
title = input()
code = input()
print('Title = {0}, Code = {1}'.format(title, code))
print('Title = {}, Code = {}'.format(title, code))
print('{0:*^30}'.format(' Title '))
print('{0:*^30}'.format(' Code ')) | 93 | pe | tuple.py | 8902f3e4130ead65812824ad | Qwen/Qwen2.5-Coder-7B |
class circle(object):
def __init__(self):
self.pi = 3.14
self.radius = radius
def area(self):
return(self.pi*self.radius**2)
a=int(input())
circulo=circle()
print(circulo.area()) | 80 | pe | tuple.py | 941cb66305750b2bec69e6fc | Qwen/Qwen2.5-Coder-7B |
name=input("enter name")
def cont(name):
count=0
for c in name:
count=count+1
return count
print(cont(name))
| 53 | pe | tuple.py | 5b8bc09c592d0a02febeb1b0 | Qwen/Qwen2.5-Coder-7B |
kod = input()
ilk_kod = input()
not_done = True
while not_done:
if kod == ilk_kod:
print("Verified")
not_done = False
else:
print("Access denied")
kod = input()
if kod == ilk_kod:
print("Verified")
not_done = False | 99 | pe | tuple.py | 886af6551f9dcee7d4d41d6e | Qwen/Qwen2.5-Coder-7B |
# find max values and names
max = int(input('How many items?'))
names = []
prices = []
for i in range(max):
names.append(input('Enter the product name: '))
prices.append(float(input('Enter the product price: ')))
highest = max(prices)
print('The most expensive product is: ', names[prices.index(highest)],'at',... | 325 | pe | tuple.py | 2a9bc2d08b13ffd81ba622ad | Qwen/Qwen2.5-Coder-7B |
L=[(2,"aaa"), (1,"bbb"), (3,"ccc"),(4,"ddd")]
print(L.sort(key=lambda x:x[1], reverse=True))
print(L)
| 66 | pe | tuple.py | d17121741fa4bb5751553288 | Qwen/Qwen2.5-Coder-7B |
class Product :
def __init__(self,name,price):
self.name=name
self.price=price
def __repr__(self):
return "Item['Product Name':'{0}''Price':'{1}']".format(self.name,self.price)
p1=Product("Milk",3)
p2=Product("Tomato",4)
print(p1,p2) | 112 | pe | tuple.py | dba9023e168bd6a685daa2c9 | Qwen/Qwen2.5-Coder-7B |
hours = input("Enter Hours:")
rate = input("Enter Rate:")
try:
h=float(hours)
r=float(rate)
gross_pay = h*r
except:
print('Error, please enter numeric input')
quit()
if h<=40:
print('Pay:',gross_pay)
else:
gross_pay = 40*r+(h-40)*r*1.5
print('Pay:',gross_pay) | 134 | pe | tuple.py | fa21b37ac168394aca7ce859 | Qwen/Qwen2.5-Coder-7B |
def collapse_segments(segments: list[tuple[int, int]]) -> list[tuple[int, int]]:
"""Merge overlapping segments in a list into a new list with non-overlapping segments.
Segments are represented as tuples of two integers, where the first integer is the start
point and the second integer is the end point.
... | 191 | tp | collapse_segments.py | 4bd353e3c20a9631e6e70cdc | Qwen/Qwen2.5-Coder-7B |
def collapse_segments(segments: list[tuple[int, int]]) -> list[tuple[int, int]]:
"""Combine overlapping or adjacent segments into minimal segments that cover
the same range, but do not overlap or overlap only at endpoints.
"""
result: list[tuple[int, int]] = []
if segments:
segments.sort(key... | 213 | tp | collapse_segments.py | 707d1c487ca5d569bea66715 | Qwen/Qwen2.5-Coder-7B |
def collapse_segments(segments: list[tuple[int, int]]) -> list[tuple[int, int]]:
"""Collapse overlapping line segments in a list of tuples (start, stop) into a
consolidated list of non-overlapping segments.
"""
if not segments:
return []
# Sort by start time, then by stop time (for tiebreaks... | 301 | tp | collapse_segments.py | c55741260237b14957723a4e | Qwen/Qwen2.5-Coder-7B |
def remove_short_segments(segment_lengths: list[int], min_length: int) -> list[int]:
"""Filter a list of integers, removing any integer that represents a segment
with length less than a specified minimum length.
"""
filtered = [length for length in segment_lengths if length >= min_length]
return fil... | 100 | tp | collapse_segments.py | f5bd5c5e041f419a6cb66582 | Qwen/Qwen2.5-Coder-7B |
def collapse_segments(segments: list[tuple[int, int]]) -> list[tuple[int, int]]:
"""Given a list of tuples representing segments with start and end points,
consolidate overlapping segments and return a list of tuples with no
overlapping ranges.
"""
sorted_segments = sorted(segments)
consolidated... | 196 | tp | collapse_segments.py | f061929ca6d538f519a60132 | Qwen/Qwen2.5-Coder-7B |
def collapse_segments(segments: list[tuple[int, int]]) -> list[tuple[int, int]]:
"""Given a list of segments as tuples of integers representing start and end points,
merge overlapping segments and return a new list of non-overlapping segments.
"""
sorted_segments = sorted(segments)
result: list[tupl... | 233 | tp | collapse_segments.py | a2e7641982b56969aad507c5 | Qwen/Qwen2.5-Coder-7B |
def collapse_segments(segments: list[tuple[int, int]]) -> list[tuple[int, int]]:
"""Given a list of overlapping segments defined by their start and end points,
return a condensed list with non-overlapping segments covering the same range.
"""
segments.sort(key=lambda x: x[0])
collapsed: list[tuple[i... | 191 | tp | collapse_segments.py | 4fe368718767c26bef723c3f | Qwen/Qwen2.5-Coder-7B |
def collapse_segments(segments: list[tuple[int, int]]) -> list[tuple[int, int]]:
"""Given a list of non-overlapping segments represented by tuples (start, end),
merge them into a list of non-overlapping segments without gaps.
"""
segments.sort(key=lambda x: x[0])
collapsed = []
for segment in se... | 189 | tp | collapse_segments.py | 33551d06952d77aff67504f0 | Qwen/Qwen2.5-Coder-7B |
def collapse_segments(num_segments: int, sum_fragments: list[int]) -> int:
"""Given a list of integers representing the sum of fragments in each segment,
calculate the minimum number of changes required to balance all segments. If the
total sum of fragments is divisible by the number of segments, return zer... | 172 | tp | collapse_segments.py | b3ec7a58fdbfcf7a61cf9e9d | Qwen/Qwen2.5-Coder-7B |
def collapse_segments(points: list[int]) -> list[tuple[int, int]]:
"""Collapse a list of ordered integer pairs into a minimal set of contiguous
segments. Each pair consists of two integer values denoting the start and end of
a segment. Overlapping segments should be consolidated into a single segment with
... | 230 | tp | collapse_segments.py | f99254d54e6b582735ecc458 | Qwen/Qwen2.5-Coder-7B |
def collapse_segments(segments: list[list[int]]) -> list[list[int]]:
"""Collapse overlapping segments into a new list of segments.
Consider a segment of the form: [start, end].
"""
result: list[list[int]] = []
if not segments:
return result
sorted_segments = sorted(segments, key=lambda x... | 182 | tp | collapse_segments.py | 7df46eb27c4ff2ed37145f3c | Qwen/Qwen2.5-Coder-7B |
def collapse_segments(segments: list[tuple[int, int]]) -> list[tuple[int, int]]:
"""Collapses overlapping or adjacent segments from a list of tuples into
non-overlapping segments.
"""
if not segments:
return []
result: list[tuple[int, int]] = []
segments.sort(key=lambda x: x[0])
cu... | 187 | tp | collapse_segments.py | 5ca654c7e1c137c5df96e1f2 | Qwen/Qwen2.5-Coder-7B |
def collapse_segments(segments: list[list[float]]) -> list[list[float]]:
"""Collapse a sequence of line segments to a single line segment.
The segments should be sorted by their starting point. They can overlap.
Consider edge cases where the result segment may have length 0.
"""
if not segments:
... | 177 | tp | collapse_segments.py | 0e5234fde233d4081be30583 | Qwen/Qwen2.5-Coder-7B |
def collapse_segments(segments: list[list[int]]) -> list[tuple[int, int]]:
"""Collapse a list of segments into smaller lists of collapsed ranges.
For example: [[1, 2], [3, 5], [6, 8]] will collapse into
[(1, 2), (3, 5), (6, 8)].
Don't assume the segments will be sorted.
Example:
>>> collapse_... | 494 | tp | collapse_segments.py | cbe2935c0af9b6e6b608947a | Qwen/Qwen2.5-Coder-7B |
"""
143. Reorder List
https://leetcode.com/problems/reorder-list/
Medium
Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…
You may not modify the values in the list's nodes, only nodes itself may be changed.
Example 1:
Given 1->2->3->4, reorder it to 1->4->2->3.
Example 2:
Give... | 499 | pe | passing_params.py | d5d3b11cc123ac03a0903ec9 | Qwen/Qwen2.5-Coder-7B |
'''
by defalut all params are passed by reference
'''
def increment(n):
print('i have n = ', n)
print('and i will increment it')
n += 1
print('and now it is:', n)
def pass_by_refrence():
n = 10
print('i have n = ', n)
increment(n)
print('after calling the increment function: ', n)
... | 191 | pe | passing_params.py | cb53a5294f0ddd4d1c7f5673 | Qwen/Qwen2.5-Coder-7B |
def passing_parameters_to_lambda(a):
a(1,2,3)
def passing_lambda_lambda(a, b, c):
print(a+b+c)
a = lambda x,y,z: x+y+z
passing_parameters_to_lambda(a) | 68 | pe | passing_params.py | 7b25a971ea52f3cf6772f46e | Qwen/Qwen2.5-Coder-7B |
def swap(x,y):
temp=x
x=y
y=temp
return x,y
a,b=swap(10,20)
print(a,b)
| 56 | pe | passing_params.py | 997dcae0bdc5f1de0d8b3960 | Qwen/Qwen2.5-Coder-7B |
import time
start_time = time.time()
def bar():
return int(1e9)
bar()
elapsed_time = time.time() - start_time
print(elapsed_time) | 43 | pe | passing_params.py | 45bf07b272e1a041b819a976 | Qwen/Qwen2.5-Coder-7B |
def func():
arg1 = None
arg2 = None
return arg1, arg2
arg1, arg2 = func()
print(arg1, arg2) | 47 | pe | passing_params.py | a24dd51c52860db8ecc66373 | Qwen/Qwen2.5-Coder-7B |
def multiply(x,y):
print("%d*%d = %d" %(x,y,x*y))
x=int(input("Enter First Number: "))
y=int(input("Enter Second Number: "))
multiply(x,y) | 73 | pe | passing_params.py | 756846b76cf6c789c962c7c9 | Qwen/Qwen2.5-Coder-7B |
def foo(value):
return f"I was passed this value: {value}"
print(foo)
print([foo(1), foo(2), foo("HI!")])
print(foo("next thing")) | 63 | pe | passing_params.py | 140172a027a2029d6c4114e2 | Qwen/Qwen2.5-Coder-7B |
'''
How to pass function reference as parameter.
'''
def foo(x):
print('foo called with ', x)
def bar(x):
print('bar called with ', x)
def foobar(a, b):
if a < b:
print('foo')
foo(a)
else:
print('bar')
bar(b)
foobar(1, 10) | 110 | pe | passing_params.py | 2ed7cc056de75cff7271d1bd | Qwen/Qwen2.5-Coder-7B |
def print_name(name, age):
print("Hello", name, age)
# Calling function using positional arguments
print_name("ali", 20)
# Calling function using keyword argument
print_name(name="John", age=30)
# Calling function using mixed arguments
print_name("John", age=30)
# Default value
def print_name(name, age=20):
... | 190 | pe | passing_params.py | f8658d49883b7c4aae74f2ec | Qwen/Qwen2.5-Coder-7B |
"""
Procedure for passing parameters into a function.
Arguments can be passed in the following ways:
1. Positional
* positional arguments must appear first and are bound by position in the function header
2. Default (optional)
* default arguments must follow positional... | 500 | pe | passing_params.py | efd30472740524ff0a6146a5 | Qwen/Qwen2.5-Coder-7B |
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution(object):
def isValidBST(self, root):
"""
:type root: TreeNode
:rtype: bool
... | 619 | pe | passing_params.py | 952b051752e7f48d5290dc5c | Qwen/Qwen2.5-Coder-7B |
'''
@Description:
@Author: k.chen
@Date: 2020-01-10 22:22:05
@LastEditTime : 2020-01-10 22:52:03
'''
#
# @lc app=leetcode.cn id=21 lang=python3
#
# [21] 合并两个有序链表
#
# @lc code=start
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
cl... | 401 | pe | ch-2.py | 4a241682c9cf0b1563264500 | Qwen/Qwen2.5-Coder-7B |
#!/usr/bin/python3
fileObject = open("tmpfile.txt","w")
fileObject.write("Hello World!\n")
fileObject.write("This is Python programing\n")
fileObject.close()
fileObject = open("tmpfile.txt","r")
text = fileObject.read()
fileObject.close()
print(text) | 110 | pe | ch-2.py | 3471e1c1d79d618e0904f2e7 | Qwen/Qwen2.5-Coder-7B |
'''
@Description:
@Author: k.chen
@Date: 2020-01-04 16:52:52
@LastEditTime : 2020-01-04 17:00:37
'''
#Given an array of integers, return indices of the two numbers such that they add up to a specific target.
#You may assume that each input would have exactly one solution, and you may not use the same element twice.
c... | 232 | pe | ch-2.py | 91a61a965a14b7c91c891d9b | Qwen/Qwen2.5-Coder-7B |
'''ch-2'''
'''FizzBuzz'''
for i in range(1, 101):
if (i % 5 == 0 and i % 3 == 0):
print("FizzBuzz")
elif i % 5 == 0:
print("Buzz")
elif i % 3 == 0:
print("Fizz")
else:
print(i) | 105 | pe | ch-2.py | f609d1adf9f9d13d039c57fb | Qwen/Qwen2.5-Coder-7B |
def correct_hash(str):
ba=[]
ba=(ord(str)/len(str))
return ba
print(correct_hash('Python')) | 45 | pe | ch-2.py | 8da8b49169eac7238e230bae | Qwen/Qwen2.5-Coder-7B |
print ("File handling")
print ("Creating a file")
open("spam.txt", "w")
print ("Writing to a file")
f = open("spam.txt", "w")
f.write("hello world\n") # This is added at the end of the file
f.write("Bye bye!\n")
f.close()
print ("Reading the contents of a file")
f = open("spam.txt", "r")
text = f.read()
f.close()
pr... | 161 | pe | ch-2.py | b91f3a225d60b30014edc9f2 | Qwen/Qwen2.5-Coder-7B |
data="aku sayang kamu"
data_2="aku cinta kamu"
print(data.upper())
print(data.lower())
data3=data.center(50,"~")
data4=data_2.center(50,"~")
print(data3)
print(data4)
print(data[0:4])
print(data3[:32])
print(data3[47:50])
data5=data.replace("aku","mereka")
print(data5) | 113 | pe | ch-2.py | d2048ebb9fac00e7d16ffa73 | Qwen/Qwen2.5-Coder-7B |
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def removeElements(self, head: ListNode, val: int) -> ListNode:
dummy = ListNode(-1)
dummy.next = head
prev_node = dummy
... | 179 | pe | Program226.py | a19008f0b4865766393d131e | Qwen/Qwen2.5-Coder-7B |
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution(object):
def reverseList(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
node=head
sta... | 213 | pe | Program226.py | 12c0a79d1bfab71cd2e94c71 | Qwen/Qwen2.5-Coder-7B |
a = {"one": [1, 11], "two": [2, 22]}
new_dict = a.copy()
a["three"] = [3, 33]
print(a)
print(new_dict)
a["one"][1] = 20
print(a)
print(new_dict) | 66 | pe | Program226.py | 748d18b11aa512bcf1d4809d | Qwen/Qwen2.5-Coder-7B |
def countelement(list1):
frequency = {}
for item in list1:
if (item in frequency):
frequency[item] += 1
else:
frequency[item] = 1
print(frequency) | 67 | pe | Program226.py | 17fcdeb2384ad06f652b90a3 | Qwen/Qwen2.5-Coder-7B |
#We use this when we want to solve a dynamic programming question and have to make
#recursive calls for finding the solution.
def fib(n):
if n == 0:
return 0
elif n == 1:
return 1
else:
return fib(n - 1) + fib(n - 2)
for i in range(5):
print(str(i) + ":", fib(i)) | 123 | pe | Program226.py | 87e05727e1f42487d6fe0221 | Qwen/Qwen2.5-Coder-7B |
# Python3 program to count Substrings in
# given string which are prefix of the
# string.
# Returns count of substrings of str which
# are prefix of str itself.
def countPrefix(str):
n = len(str)
res = n
for i in range(1, n):
j = i
k = i-1
# Check for palindromic su... | 307 | pe | Program226.py | 77a908e0277e71f1145a5511 | Qwen/Qwen2.5-Coder-7B |
class Solution(object):
def invertTree(self, root):
"""
:type root: TreeNode
:rtype: TreeNode
"""
if root:
root.left, root.right = root.right, root.left
self.invertTree(root.left)
self.invertTree(root.right)
return root | 88 | pe | Program226.py | 8e0ded5981c4f6038bf9f883 | Qwen/Qwen2.5-Coder-7B |
from collections import defaultdict
class Graph:
def __init__(self):
self.graph = defaultdict(list)
def addEdge(self, node, neighbour):
self.graph[node].append(neighbour)
def BFS(graph, node):
vis = [False] * (max(graph.graph.keys())+1)
qu... | 244 | pe | Program226.py | bbb99276ee5364cbd85704d1 | Qwen/Qwen2.5-Coder-7B |
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution(object):
def isSameTree(self, p, q):
"""
:type p: TreeNode
:type q: TreeNode
:rtype: bool
... | 180 | pe | Program226.py | 985c8e2674526787b2a59f2c | Qwen/Qwen2.5-Coder-7B |
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution(object):
def invertTree(self, root):
"""
:type root: TreeNode
:rtype: TreeNode
"""
... | 248 | pe | Program226.py | f5f28d5098cc222ecc807e03 | Qwen/Qwen2.5-Coder-7B |
def filter_records(data: dict[str, list[float]]) -> dict[str, float]:
"""Return a dictionary containing the mean of each column in a given dictionary
where each value is a list of float numbers.
"""
result = {}
for key, values in data.items():
if all(isinstance(x, float) for x in values):
... | 105 | mix | filter_records.py | 14d68ba92efe1a432ea77e64 | Qwen/Qwen2.5-Coder-7B |
def filter_records(records: list[tuple[str, int]], num: int) -> list[tuple[str, int]]:
"""Return a list of records from a list of tuples where the numeric element is
less than or equal to a given integer.
"""
return [record for record in records if record[1] <= num] | 101 | mix | filter_records.py | bacb55cd5e31e4688d70404f | Qwen/Qwen2.5-Coder-7B |
import math
from statistics import mean
N = int(input())
data = []
M = int(input())
student_marks = {}
for _ in range(N):
name, *line = input().split()
scores = list(map(float, line))
student_marks[name] = scores
query_name = input()
print(f'{mean(student_marks[query_name]):.2f}') | 100 | mix | filter_records.py | ed3105ea1a0ca62183cb782f | Qwen/Qwen2.5-Coder-7B |
def filter_records(records: list[dict[str, any]], names: list[str]) -> dict[str, any]:
"""Return a new dictionary consisting of records whose names are not present in
the given list of names.
"""
filtered_records: dict[str, any] = {}
for record in records:
if record['name'] not in names:
... | 137 | mix | filter_records.py | f43113ce6b2ba1e21b7df5ed | Qwen/Qwen2.5-Coder-7B |
def filter_records(records: list[dict], keys: list[str]) -> list[dict]:
"""Filter a list of dictionaries by keeping only the specified keys.
"""
filtered = []
for record in records:
filtered_record = {key: record[key] for key in keys if key in record}
filtered.append(filtered_record)
... | 122 | mix | filter_records.py | 6e639ad92ac0d105fc480fee | Qwen/Qwen2.5-Coder-7B |
simple-python-synth
Synthetic, short, simple Python files, generated as an open stand-in for the "especially simple and repetitive idioms" component of the training data in Weight-sparse transformers have interpretable circuits (Gao et al., 2025, arXiv 2511.13653, appendix A.6). That component (10B tokens, written by GPT-4-base) was not released; this dataset imitates it with open models.
Size
Lengths are in the tinypython_2k tokenizer (see below).
| split | rows | tokens |
|---|---|---|
| train (98 files) | 38,967,435 | 6.63B |
| validation (2 files) | 195,892 | 33.2M |
By generator: Qwen2.5-Coder-7B 13.7M rows / 2.25B tokens,
Qwen2.5-Coder-1.5B 25.4M rows / 4.41B tokens. By prompt style: pe
3.21B, mix 1.76B, tp 1.69B tokens. Mean length ~170 tokens.
Shuffle before training: the files are not shuffled. Each file holds samples from one or a few generator processes, so consecutive files alternate between the two models.
Generated in ~9 hours on 8x H200 (4 GPUs per model).
How it was made
- Generators: base (not instruct) code models,
Qwen/Qwen2.5-Coder-7B(FP8 weights) andQwen/Qwen2.5-Coder-1.5B; themodelcolumn says which. Sampling: temperature 1.0, top-p 0.95, at most 768 generator tokens. - Prompts: few-shot in the generator's repository format: several short
files, each
<|file_sep|>name.pyfollowed by the code, then<|file_sep|>new_name.pyand the model writes that file; generation stops at the next file separator. Exemplars come from a pool of 3.9M short, simple files: 2.79M real files from Avelina/python-edu-cleaned and 1.11M functions from BertilBraun/TinyPython (description added as a docstring), all passing the filter below. Thestylecolumn gives the prompt mix:pe(3-6 real files),tp(8-12 TinyPython functions),mix(both);nameis the file name the model was asked to write (taken from another pool file). - Filter (every sample): parses as Python 3; 40-1024 tokens of the
tinypython_2ktokenizer; at most 100 lines of at most 120 characters; block nesting at most 4; imports only from a small stdlib set; no literal with more than 24 elements; non-docstring string literals under 45% of the characters; under 1% non-ASCII; no heavy line repetition or extreme compressibility; at least 3 statements. Samples cut off by the length limit are dropped. - Dedup: exact, on the code with comments and blank lines removed
(
hashcolumn); samples identical to a pool exemplar are dropped. - Split: ~0.5% of samples, chosen by hash, are in
validation.
ntok is the length in the tinypython_2k tokenizer from
openai/circuit_sparsity
(circuit_sparsity/tiktoken_ext/tinypython.py; vocabulary files at
https://openaipublic.blob.core.windows.net/circuit-sparsity/tinypython/).
Caveats
- Not the paper's data: much weaker generators than GPT-4-base, and the exemplars steer the style toward beginner / exercise code.
- The 1.5B samples are less coherent (docstrings that do not match the code,
odd logic); filter on
modelif that matters. - Files are not executed; only parsed.
- Downloads last month
- 352