c to python converter

import sys

def mergesort_2ndstep(l, r):
	len_l = len(l)
	len_r = len(r)
	# initializing a list of length zero
	sorted_array = []
	i,j = 0,0
	while i < len_l:
		num1 = l[i]
		for x in range(j,len_r):
			num2 = r[x]
			if num2 < num1 :
				sorted_array.append(num2)
				j += 1
		
		sorted_array.append(num1)
		i += 1

	if len(sorted_array) != len_l + len_r:
		# Checking extreme conditions
		sorted_array[i+j:] = r[j:]
	return sorted_array


def mergesort_1ststep(L,start,stop):
	# a list can be divided into two 
	# if length of list is atleast two
	if stop - start > 1:
		l = mergesort_1ststep(L,start,start + (stop-start)//2)
		r = mergesort_1ststep(L,start + (stop-start)//2,stop)
		# mergeing two lists(sorting the l and r parts)
		L[start:stop] = mergesort_2ndstep(l,r)
	return L[start:stop]

# START
List_of_nums = []
file_to_open = "input1.txt"

try:
	read_file = open(file_to_open,"r")
	write_file = open("sameeraz.txt","w")
	if read_file != None:
		# appending every num from file to list_of_nums
		for line in read_file:
			line = int(line)
			List_of_nums.append(line)
		# applying mergesort
		mergesort_1ststep(List_of_nums,0, len(List_of_nums))
		# writing to an output file
		# excluding the last element 
		k = List_of_nums.pop()
		for num in List_of_nums:
			write_file.write(f"{num}\n")
		# writing last element without next line
		write_file.write(f"{k}")
	
		read_file.close()
		write_file.close()
except:
	print("file not found")

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source