简体   繁体   中英

TypeError: '>' not supported between instances of 'int' and 'list'

Im having problem with this code right here, how can i change the list to an int so that it can be processed. I tried multiple variation that can turn the list into integer but nothing is working. Thanks

 items = []

if option == 'y':
    length = 50
    items = [randrange(-100, 101 + 1) for i in range(length)]
else:
    print('wrong, bye')
    exit()

subset2 = 2
print('\nset: {' + ', '.join(map(str, items)) + '}')
items = list(map(int, items))
overallHighestSum = 0
while subset2 != length:
    sets = []
    currentHighestSum = 0

    for i in range(length):
        if length > i + subset2 - 1:
            terms = []
            termSum = 0
            terms = list(map(int, terms))

            for j in range(length):
                currentItem = items[j + 1]
                terms.append(currentItem)

                sets.append(terms)

                if sum(terms) > currentHighestSum:
                    currentHighestSum = sum(terms)

                if sum(terms) > overallHighestSum:
                    overallHighestSum = sum(terms)
                    overallHighestSum = terms

You are changing the contents of overallHighestSum in

if sum(terms) > overallHighestSum:
    overallHighestSum = sum(terms)
    overallHighestSum = terms

remove overallHighestSum = terms and make it as follows:

if sum(terms) > overallHighestSum:
    overallHighestSum = sum(terms)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM