Python Forum
adding parts of a list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
adding parts of a list
#4
(Nov-17-2019, 08:37 AM)buran Wrote: you can use list comprehension
scores = [int(score) for score in data[1:]]
or map
scores = map(int, data[1:5])
then
grade = sum(scores)

Thanks. It was able to add all the scores. Is there a way to get it to add the scores on each line separately? I tried putting the code into the for loop but it still just prints the total.
Reply


Messages In This Thread
adding parts of a list - by Eric7Giants - Nov-16-2019, 08:40 PM
RE: adding parts of a list - by buran - Nov-17-2019, 08:37 AM
RE: adding parts of a list - by ichabod801 - Nov-17-2019, 02:35 PM
RE: adding parts of a list - by Eric7Giants - Nov-17-2019, 04:37 PM
RE: adding parts of a list - by buran - Nov-17-2019, 05:53 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  help with adding duplicates elements together in a list 2ECC3O 5 2,235 Sep-10-2022, 07:11 AM
Last Post: 2ECC3O
  Python Adding +1 to a list item cointained in a dict ElReyZero 1 2,175 Apr-30-2020, 05:12 AM
Last Post: deanhystad
  Adding values to list and pickling mefiak 2 2,931 May-31-2018, 08:57 AM
Last Post: mefiak
  adding a number to the list atux_null 4 4,056 Nov-06-2017, 07:01 PM
Last Post: gruntfutuk

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020