Python Forum
Making lists using itertools and eliminating duplicates.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Making lists using itertools and eliminating duplicates.
#1
I'm trying to get all combinations of the following numbers as long as they don't total over 50,000 and must be in combos of 6. From there I want to condense into a new list that has no duplicates even if they're are out of order (ex: [8000, 9300, 7000, 8800, 7400, 9200] would be eliminated if [8800, 7400, 9200, 8000, 9300, 7000] was already in the list).

I think my code is correct but it is taking forever for the ouput to load in PyCharm. For now, I'm just looking to see if the len of the lists will be different to see if it is worth eliminating duplicates.

Sorry but I don't know how to get it to hold the indents when I post.

import itertools

num = {
9200, 8200, 7600, 9100, 7400, 8900, 7900,
7500, 7700, 6800, 9300, 9000, 7000, 8000,
8600, 7100, 8800, 7300, 8300, 8700, 8500,
9400, 6900, 7200
}

entry = []
for i in num:
for combination in itertools.combinations(num, 6):
if sum(combination) <= 50000:
entry.append(combination)

non_dup = []
for i in entry:
if i not in non_dup:
non_dup.append(i)



print("Entry list: " + str(len(entry)))
print("Non-Dup list: " + str(len(non_dup)))
Reply


Messages In This Thread
Making lists using itertools and eliminating duplicates. - by mike3891 - Oct-26-2020, 04:30 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  remove partial duplicates from csv ledgreve 0 820 Dec-12-2022, 04:21 PM
Last Post: ledgreve
  itertools and amazing speed Pedroski55 8 2,110 Nov-11-2022, 01:20 PM
Last Post: Gribouillis
  Problem : Count the number of Duplicates NeedHelpPython 3 4,425 Dec-16-2021, 06:53 AM
Last Post: Gribouillis
  Eliminating error in Python update-alternatives Led_Zeppelin 2 3,024 Apr-14-2021, 12:49 PM
Last Post: Led_Zeppelin
  Removal of duplicates teebee891 1 1,819 Feb-01-2021, 12:06 PM
Last Post: jefsummers
  eliminating letters when typed in python window deebo 0 1,755 Jan-05-2021, 09:26 AM
Last Post: deebo
  What happens to a <itertools.permutations object at 0x7fe3cc66af68> after it is read? Pedroski55 3 2,436 Nov-29-2020, 08:35 AM
Last Post: DeaD_EyE
  Displaying duplicates in dictionary lokesh 2 2,024 Oct-15-2020, 08:07 AM
Last Post: DeaD_EyE
  Split dict of lists into smaller dicts of lists. pcs3rd 3 2,425 Sep-19-2020, 09:12 AM
Last Post: ibreeden
  Python3 itertools.groupby printing the key august 1 2,114 Aug-17-2020, 05:46 AM
Last Post: bowlofred

Forum Jump:

User Panel Messages

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