r/PythonJobs • • Jan 25 '22

help me i need help with some school work

Make a program that lets a user input a series of names into a list. The program should then

ask the user whether they want to print out the list in the original order, or in reverse.

Extensions:

  1. Enable the user to choose what number item in the list they want to print out

  2. Enable the user to only print out a 'slice' of the list (eg item three to item nine only)

  3. Enable the user to remove any items of the list that they want to

  4. Enable the user to save their list to a file for later, and also enable them to load it back up

again too

5. 'Clean' the list by making all the items lowercase.

all this above is what i need to do but i only understand the first extension bit and the first sentence

i need understanding of number 2 if some one could help then pls do i need it for tomorrow lol

also, the list i made consists of words not letters so when i do splicing it just gives letters from the list and not individual words pls help

6 Upvotes

4 comments sorted by

2

u/sahnisanchit Jan 25 '22

For printing out of a slice of list, Use a loop with range of items you want to loop through and print out items.

For x in list[start+1 :end+1]: print x

Take start and end as input from user, from where till where to show the list. +1 because it's index value and user won't input index values

1

u/[deleted] Jan 25 '22

ty I'll try

2

u/AutoModerator Jan 25 '22

Rule for bot users and recruiters: to make this sub readable by humans and therefore beneficial for all parties, only one post per day per recruiter is allowed. You have to group all your job offers inside one text post.

Here is an example of what is expected, you can use Markdown to make a table.

Subs where this policy applies: /r/MachineLearningJobs, /r/RemotePython, /r/BigDataJobs, /r/WebDeveloperJobs/, /r/JavascriptJobs, /r/PythonJobs

Recommended format and tags: [Hiring] [ForHire] [Remote] [Flask] [Django]

For fully remote positions, remember /r/RemotePython

Happy Job Hunting.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/Interesting-Ask2405 Jan 26 '22

List1=["item1,"item2","item3","item4","item5"]

slicing

List1[2:3]#output >> item2 List1[2:4]#output >> item2,item3

Deleting item from the list

Todel=input() If Todel in List1 == True: List1.remove(Todel) Else: Print("not in the list")

select item from index

Nindex=int(input()) If Nindex-1 >= len(List1): Print("index out of bound") Else: Print(List[Nindex-1])

save and load from and to a file

saving list

f=open("filelist.txt","w") For item in List1:

f.write(item+"\n")

f.close()

load list

Newlist=[] f.open("filelist.txt","r") Items=f.readlines() For item in items: Newlist.append(item) f.close() List1=Newlist.copy() Del Newlist

lowercase

For i, item in enumerate(List1): List1[i]=item.lower()

It will probably work xd