Skip to content

Commit ecda8ad

Browse files
committed
2 parents 3952cfa + 7aafe26 commit ecda8ad

8 files changed

+270
-25
lines changed

CODE_OF_CONDUCT.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Contributor Covenant Code of Conduct
1+
# Contributor Covenant Code of Conduct Easy to understand
22

33
## Our Pledge
44

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Contributing
1+
# Contributing Notepad Sorting
22

33
When contributing to this repository, please first discuss the change you wish to make via issue,
44
email, or any other method with the owners of this repository before making a change.

PDF/demerge_pdfs.py

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""
2+
Python program to split large pdf(typically textbook) into small set of pdfs, maybe chapterwise
3+
to enhance the experience of reading and feasibility to study only specific parts from the large original textbook
4+
"""
5+
6+
7+
import PyPDF2
8+
path = input()
9+
merged_pdf = open(path, mode='rb')
10+
11+
12+
pdf = PyPDF2.PdfFileReader(merged_pdf)
13+
14+
(u, ctr, x) = tuple([0]*3)
15+
for i in range(1, pdf.numPages+1):
16+
17+
if u >= pdf.numPages:
18+
print("Successfully done!")
19+
exit(0)
20+
name = input("Enter the name of the pdf: ")
21+
ctr = int(input(f"Enter the number of pages for {name}: "))
22+
u += ctr
23+
if u > pdf.numPages:
24+
print('Limit exceeded! ')
25+
break
26+
27+
base_path = '/Users/darpan/Desktop/{}.pdf'
28+
path = base_path.format(name)
29+
f = open(path, mode='wb')
30+
pdf_writer = PyPDF2.PdfFileWriter()
31+
32+
for j in range(x, x+ctr):
33+
page = pdf.getPage(j)
34+
pdf_writer.addPage(page)
35+
36+
x += ctr
37+
38+
pdf_writer.write(f)
39+
f.close()
40+
41+
42+
merged_pdf.close()
43+
print("Successfully done!")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
"""
2+
Given a linked list with head pointer,
3+
sort the linked list using quicksort technique without using any extra space
4+
Time complexity: O(NlogN), Space complexity: O(1)
5+
"""
6+
from __future__ import annotations
7+
8+
9+
class Node:
10+
def __init__(self, data: int) -> None:
11+
self.data = data
12+
self.next = None
13+
14+
15+
class LinkedList:
16+
def __init__(self):
17+
self.head = None
18+
19+
# method to insert nodes at the start of linkedlist
20+
def insert(self, new_data: int) -> None:
21+
new_node = Node(new_data)
22+
new_node.next = self.head
23+
self.head = new_node
24+
25+
# method to print the linkedlist
26+
def printLL(self) -> None:
27+
temp = self.head
28+
if temp == None:
29+
return 'Linked List is empty'
30+
while temp.next:
31+
print(temp.data, '->', end='')
32+
temp = temp.next
33+
print(temp.data)
34+
return
35+
36+
# Partition algorithm with pivot as first element
37+
38+
39+
def partition(start, end):
40+
if start == None or start.next == None:
41+
return start
42+
prev, curr = start, start.next
43+
pivot = prev.data
44+
while curr != end:
45+
if curr.data < pivot:
46+
prev = prev.next
47+
temp = prev.data
48+
prev.data = curr.data
49+
curr.data = temp
50+
curr = curr.next
51+
temp = prev.data
52+
prev.data = start.data
53+
start.data = temp
54+
return prev
55+
56+
57+
# recursive quicksort for function calls
58+
def quicksort_LL(start, end):
59+
if start != end:
60+
pos = partition(start, end)
61+
quicksort_LL(start, pos)
62+
quicksort_LL(pos.next, end)
63+
return
64+
65+
66+
if __name__ == "__main__":
67+
ll = LinkedList()
68+
print("Enter the space seperated values of numbers to be inserted in linkedlist prompted below:")
69+
arr = list(map(int, input().split()))
70+
for num in arr:
71+
ll.insert(num)
72+
print("Linkedlist before sorting:")
73+
ll.printLL()
74+
quicksort_LL(ll.head, None)
75+
print('Linkedlist after sorting: ')
76+
ll.printLL()

Swap numbers.py

-22
This file was deleted.

agecalculator.py

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
from _datetime import datetime
2+
import tkinter as tk
3+
from tkinter import ttk
4+
from _datetime import *
5+
6+
win = tk.Tk()
7+
win.title('Age Calculate')
8+
win.geometry('310x400')
9+
# win.iconbitmap('pic.png') this is use extention ico then show pic
10+
11+
############################################ Frame ############################################
12+
pic = tk.PhotoImage(file=r"E:\Python Practice\Age_calculate\pic.png")
13+
win.tk.call('wm','iconphoto',win._w,pic)
14+
15+
16+
canvas=tk.Canvas(win,width=310,height=190)
17+
canvas.grid()
18+
image = tk.PhotoImage(file=r"E:\Python Practice\Age_calculate\pic.png")
19+
canvas.create_image(0,0,anchor='nw',image=image)
20+
21+
frame = ttk.Frame(win)
22+
frame.place(x=40,y=220)
23+
24+
25+
26+
############################################ Label on Frame ############################################
27+
28+
name = ttk.Label(frame,text = 'Name : ',font = ('',12,'bold'))
29+
name.grid(row=0,column=0,sticky = tk.W)
30+
31+
year = ttk.Label(frame,text = 'Year : ',font = ('',12,'bold'))
32+
year.grid(row=1,column=0,sticky = tk.W)
33+
34+
month = ttk.Label(frame,text = 'Month : ',font = ('',12,'bold'))
35+
month.grid(row=2,column=0,sticky = tk.W)
36+
37+
date = ttk.Label(frame,text = 'Date : ',font = ('',12,'bold'))
38+
date.grid(row=3,column=0,sticky = tk.W)
39+
40+
############################################ Entry Box ############################################
41+
name_entry = ttk.Entry(frame,width=25)
42+
name_entry.grid(row=0,column=1)
43+
name_entry.focus()
44+
45+
year_entry = ttk.Entry(frame,width=25)
46+
year_entry.grid(row=1,column=1,pady=5)
47+
48+
month_entry = ttk.Entry(frame,width=25)
49+
month_entry.grid(row=2,column=1)
50+
51+
date_entry = ttk.Entry(frame,width=25)
52+
date_entry.grid(row=3,column=1,pady=5)
53+
54+
55+
def age_cal():
56+
name_entry.get()
57+
year_entry.get()
58+
month_entry.get()
59+
date_entry.get()
60+
cal = datetime.today()-(int(year_entry))
61+
print(cal)
62+
63+
64+
btn = ttk.Button(frame,text='Age calculate',command=age_cal)
65+
btn.grid(row=4,column=1)
66+
67+
68+
69+
win.mainloop()

snake_case_renamer_depth_one.py

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import os
2+
import argparse
3+
from typing import Union
4+
5+
def generate_unique_name(directory: str, name: str) -> str:
6+
"""
7+
Generate a unique name for a file or folder in the specified directory.
8+
9+
Parameters:
10+
----------
11+
directory : str
12+
The path to the directory.
13+
name : str
14+
The name of the file or folder.
15+
16+
Returns:
17+
-------
18+
str
19+
The unique name with an index.
20+
"""
21+
base_name, extension = os.path.splitext(name)
22+
index = 1
23+
while os.path.exists(os.path.join(directory, f"{base_name}_{index}{extension}")):
24+
index += 1
25+
return f"{base_name}_{index}{extension}"
26+
27+
def rename_files_and_folders(directory: str) -> None:
28+
"""
29+
Rename files and folders in the specified directory to lowercase with underscores.
30+
31+
Parameters:
32+
----------
33+
directory : str
34+
The path to the directory containing the files and folders to be renamed.
35+
36+
Returns:
37+
-------
38+
None
39+
"""
40+
if not os.path.isdir(directory):
41+
raise ValueError("Invalid directory path.")
42+
43+
for name in os.listdir(directory):
44+
old_path = os.path.join(directory, name)
45+
new_name = name.lower().replace(" ", "_")
46+
new_path = os.path.join(directory, new_name)
47+
48+
# Check if the new filename is different from the old filename
49+
if new_name != name:
50+
# Check if the new filename already exists in the directory
51+
if os.path.exists(new_path):
52+
# If the new filename exists, generate a unique name with an index
53+
new_path = generate_unique_name(directory, new_name)
54+
55+
os.rename(old_path, new_path)
56+
57+
def main() -> None:
58+
"""
59+
Main function to handle command-line arguments and call the renaming function.
60+
61+
Usage:
62+
------
63+
python script_name.py <directory_path>
64+
65+
Example:
66+
--------
67+
python rename_files_script.py /path/to/directory
68+
69+
"""
70+
# Create a parser for command-line arguments
71+
parser = argparse.ArgumentParser(description="Rename files and folders to lowercase with underscores.")
72+
parser.add_argument("directory", type=str, help="Path to the directory containing the files and folders to be renamed.")
73+
args = parser.parse_args()
74+
75+
# Call the rename_files_and_folders function with the provided directory path
76+
rename_files_and_folders(args.directory)
77+
78+
if __name__ == "__main__":
79+
main()

swap.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def __init__(self, x, y):
2727
The second value to be swapped.
2828
2929
"""
30-
if not isinstance(x, int) or not isinstance(y, int):
30+
if not isinstance(x, (int, float)) or not isinstance(y, (float, int)):
3131
raise ValueError("Both x and y should be integers.")
3232

3333
self.x = x

0 commit comments

Comments
 (0)