PythonExercises | 按照难度排列的经典 Python 练习题。 | Build Tool library
kandi X-RAY | PythonExercises Summary
kandi X-RAY | PythonExercises Summary
按照难度排列的经典 Python 练习题。
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Beep .
PythonExercises Key Features
PythonExercises Examples and Code Snippets
Community Discussions
Trending Discussions on PythonExercises
QUESTION
I'm new to Python and I'm trying to do the following exercise:
With the for loop, take the following list and sort it based on the sum of the values of the tuples of the list: [(1,5),(9,0),(12,3),(5,4),(13,6),(1,1)]
However, when I write the following code:
...ANSWER
Answered 2020-Jul-07 at 15:47The main issue here lies in the line for i in tuple1
.
Your tuple1
is [1,9,12,5,13,1]
. When i=9
, you list is clearly out of range(its length is only 6). Use for i in range(len(tuple1))
instead.
The full code will be
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install PythonExercises
You can use PythonExercises like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page