Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

more complicated counterbalancing - creating own list

This is my script:

    BalanceList1 = range(1,7) + range(13,19)
    BalanceList2 = range(7,13) + range(19,25)

    if self.get('subject_nr') in BalanceList1:
    # do something

    if self.get('subject_nr') in BalanceList2:
    # do something

This is my error message
TypeError: unsupported operand type(s) for +: 'range' and 'range'

Comments

  • Hi,

    In Python 3—which you're apparently using, and good for you, because it's an improvement over Python 2—many functions return special iterator objects, instead of lists. The range() function returns a range object. These iterators behave like lists in many ways, but not all, and one difference is that you cannot use + to concatenate them. Solution: first convert to a list like so:

    BalanceList1 = list(range(1,7)) + list(range(13,19))
    

    Cheers,
    Sebastiaan

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

Sign In or Register to comment.