Question
the program will reorder the list so the resulting list is sorted. { array: [ Python, C++, Java, C#, Swift, JavaScript, PHP, C, Perl, VB,
the program will reorder the list so the resulting list is sorted.
{ "array": [ "Python", "C++", "Java", "C#", "Swift", "JavaScript", "PHP", "C", "Perl", "VB", "Kotlin" ] }
expected output :
What is the name of the file? languages.json The values in languages.json are: C C# C++ Java JavaScript Kotlin PHP Perl Python Swift VB
my code:
import json
filename = input('What is the name of the file? ')
with open(filename) as f:
data = json.load(f)
print(len(data['array']))
for i in range(len(data['array']),1,-1):
print(i)
i_check = i
i_largest = i_check
for j in range(len(data['array'])-1,0,-1):
print(j)
if data['array'][j] > data['array'][i_largest]:
i_largest = j
if i_largest != i_check:
data['array'][i_largest],data['array'][i_check] = data['array'][i_check],data['array'][i_largest]
print(data['array'])
could you explain what is wrong with my code
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started