Skip to main content

return byte size

Nov 19, 2022CodeCatch
Loading...

More Python Posts

Remove numbers from files

Mar 26, 2023AustinLeath

0 likes • 0 views

import os
# Get the current directory
current_dir = os.getcwd()
# Loop through each file in the current directory
for filename in os.listdir(current_dir):
# Check if the file name starts with a number followed by a period and a space
if filename[0].isdigit() and filename[1] == '.' and filename[2] == ' ':
# Remove the number, period, and space from the file name
new_filename = filename[3:]
# Rename the file
os.rename(os.path.join(current_dir, filename), os.path.join(current_dir, new_filename))

Print pyramid pattern

Nov 19, 2022CodeCatch

0 likes • 0 views

def print_pyramid_pattern(n):
# outer loop to handle number of rows
# n in this case
for i in range(0, n):
# inner loop to handle number of columns
# values changing acc. to outer loop
for j in range(0, i+1):
# printing stars
print("* ",end="")
# ending line after each row
print("\r")
print_pyramid_pattern(10)

Append to a file

Jun 1, 2023CodeCatch

0 likes • 0 views

filename = "data.txt"
data = "Hello, World!"
with open(filename, "a") as file:
file.write(data)

Bubble sort

Nov 19, 2022CodeCatch

0 likes • 0 views

# Python program for implementation of Bubble Sort
def bubbleSort(arr):
n = len(arr)
# Traverse through all array elements
for i in range(n-1):
# range(n) also work but outer loop will repeat one time more than needed.
# Last i elements are already in place
for j in range(0, n-i-1):
# traverse the array from 0 to n-i-1
# Swap if the element found is greater
# than the next element
if arr[j] > arr[j+1] :
arr[j], arr[j+1] = arr[j+1], arr[j]
# Driver code to test above
arr = [64, 34, 25, 12, 22, 11, 90]
bubbleSort(arr)
print ("Sorted array is:")
for i in range(len(arr)):
print ("%d" %arr[i]),

Delete all even numbers

Nov 19, 2022CodeCatch

0 likes • 0 views

# Deleting all even numbers from a list
a = [1,2,3,4,5]
del a[1::2]
print(a)

Untitled

Apr 21, 2023sebastianagauyao2002-61a8

0 likes • 0 views

print("hellur")