Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A list is sorted in ascending order if it is empty or each item except the last

ID: 3533944 • Letter: A

Question

A list is sorted in ascending order if it is empty or each item except the last one is less or equal toits successor. Define a predicate isSorted that expects a list as an argument and returns True if the list issorted, or returns false otherwise. (hint: for a list of length 2 or greater, loop through the list and compare pairs of items, from left to right, and return False if the first item in a pair is greater.)
I have been working on this and this is what I have so far

def main():

fileIN = input("Enter file name: ") #Prompt for text file.

fileName = open(fileIN, 'r') #Name file to read

index = 0

uniqueWords = []

for line in fileName: #Data being read

wordlist = line.split()

words = str(wordlist)

print(wordlist)

for words in wordlist:

unWord = words.split()

while index < len(unWord):

unWord[index] = unWord[index].split(' ')

index += 1

if not unWord in wordlist:

uniqueWords.append(wordlist)

wordlist.sort()

for unWord in wordlist:

print(unWord)

main()

Explanation / Answer


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote