Skip to content
This repository has been archived by the owner on Oct 7, 2023. It is now read-only.

Create bNZkJm.py #649

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions OP9pw8/bNZkJm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def insert_at_position(lst, position, element):
if position < 0:
print("Position cannot be negative")
return lst
elif position > len(lst):
print("Position out of range, appending element to the end of the list")
lst.append(element)
else:
lst.insert(position, element)

return lst

# Test
lst = [1, 2, 3, 4, 5]
inserted_lst = insert_at_position(lst, 2, 99)
print(inserted_lst)