Python Forum
find the sum of a series of values that equal a number
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
find the sum of a series of values that equal a number
#1
Hello, i'm completely new of Python. I know that there would be a way to determine, form a series of values, which values are corresponding to a certain another value.
Example: i have a list of values, 110,230,340,200,500,450 and a another value, for example 840. I want to find for which values, of the first series, theri sum is equal to 840. Is it possibile ?
Thanks for the help.
Reply
#2
This is a well-known problem in theoretical computer science, the subset sum problem, which is known to be NP-hard, which means that no fast algorithm will solve the problem when the size of the input data is large (eg the length of the list).

I have found one package (untested) in the Python Package Index subsetsum but it relies on C++ code. You could perhaps check this package.

Apart from this, a search engine finds pure Python implementations such as this one.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Any tips to how to find out values? nevlindan 1 725 Apr-27-2023, 09:14 PM
Last Post: deanhystad
  Print names in x-axis of a time-series values hobbyist 4 1,241 Apr-22-2023, 09:29 PM
Last Post: deanhystad
  find random numbers that are = to the first 2 number of a list. Frankduc 23 3,252 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  Remove values for weekend in a panda series JaneTan 0 680 Dec-12-2022, 01:50 AM
Last Post: JaneTan
  is there equal syntax to "dir /s /b" kucingkembar 2 1,001 Aug-16-2022, 08:26 AM
Last Post: kucingkembar
  Loop through values in dictrionary and find the same as in previous row Paqqno 5 1,915 Mar-27-2022, 07:58 PM
Last Post: deanhystad
  Find if chain of characters or number Frankduc 4 1,806 Feb-11-2022, 01:55 PM
Last Post: Frankduc
  Can a variable equal 2 things? Extra 4 1,510 Jan-18-2022, 09:21 PM
Last Post: Extra
Question Help to find the largest int number in a file directory SalzmannNicholas 1 1,640 Jan-13-2022, 05:22 PM
Last Post: ndc85430
  find 2 largest equal numbers Frankduc 13 3,557 Jan-11-2022, 07:10 PM
Last Post: Frankduc

Forum Jump:

User Panel Messages

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