# TypeError: '\>=' not supported between instances of 'list' and 'float'

**URL:** <https://discourse.psychopy.org/t/typeerror-not-supported-between-instances-of-list-and-float/7035>\
**Category:** Coding\
**Created:** [March 13, 2019, 10:14pm UTC](https://discourse.psychopy.org/t/typeerror-not-supported-between-instances-of-list-and-float/7035 "2019-03-13T22:14:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![felipeviegas](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/felipeviegas/32/4793_2.png) [@felipeviegas](https://discourse.psychopy.org/u/felipeviegas)\
**Post date:** [March 13, 2019, 10:14pm UTC](https://discourse.psychopy.org/t/typeerror-not-supported-between-instances-of-list-and-float/7035/1 "2019-03-13T22:14:35Z")

</div>

Hello fellows,

Working on version 3.0.5 on a Mac

I am designing a 2-back experiment and I am using a code to present correct feedback to the first block of training. I have already used code like this on previous versions of Psychopy, in fact. Something like:

```auto
if RT.keys != None and RT.rt <= 0.15 :
    feed = 'Anticipated!'
elif RT.keys = corrResp and RT.rt > 0.15 : 
    feed = 'Correct!'

```

RT is my RT for the stimuli and feed my updateable text to give feedback.

This is not working on version 3.0.5, besides used to work on version 1.90.3. If no button is pressed, error above shows:

> TypeError: ‘\>=’ not supported between instances of ‘list’ and ‘float’

Thanks for any help or ideas.

---

<div class="post-metadata">

**Author:** ![dvbridges](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/dvbridges/32/1918_2.png) [@dvbridges](https://discourse.psychopy.org/u/dvbridges)\
**Post date:** [March 14, 2019, 9:21am UTC](https://discourse.psychopy.org/t/typeerror-not-supported-between-instances-of-list-and-float/7035/2 "2019-03-14T09:21:06Z")

</div>

Hi @felipeviegas, there are two reasons why you are getting the error. `RT.rt` is an empty list until it is populated with an RT. Actually, this depends on how you are storing your information for your keyboard. If you store first or last response, RT.rt overwrites the rt list container and stores your RT as a float. If you store all responses, the RTs are stored in a list. So, `RT.rt <= 0.15` fails without a response because Python will not attempt to comparisons between a float and an empty list. This failure is triggered because the first part of your conditional does not correctly asses whether a response has been made: `RT.keys != None` will always be `True` because `None != []`. Instead, you want to check if the list has any responses inside by checking its length:

```auto
if len(RT.keys) and RT.rt <= 0.15 :
    feed = 'Anticipated!'
elif RT.keys == corrResp and RT.rt > 0.15 : 
    feed = 'Correct!'

```

There is also a typo in your second conditional, where you assign corrResp to your RT.keys attribute, rather than check for equality (changed above).

---

<div class="post-metadata">

**Author:** ![felipeviegas](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/felipeviegas/32/4793_2.png) [@felipeviegas](https://discourse.psychopy.org/u/felipeviegas)\
**Post date:** [March 14, 2019, 10:56am UTC](https://discourse.psychopy.org/t/typeerror-not-supported-between-instances-of-list-and-float/7035/3 "2019-03-14T10:56:04Z")

</div>

Hi @dvbridgesm thank you so much for your answer. The codo:

```auto
if len(RT.keys) and RT.rt <= 0.15

```

also fails. Psychopy tells:

> TypeError: object of type ‘NoneType’ has no len()

I imagined that some of this equality checks would tell psychopy to verify if there is any answer and then (only then) try the comparison.  
My original code is more simple, I was not checking for anticipation:

```auto
if nBack.corr == 1 :
    feed = 'Correta!'
elif nBack.corr == 0 and nBack.rt > 0:
    feed = 'Errou!'
else:
    feed = 'Não respondeu!'

```

So code works no problems. I will just have to figure out some way to prevent anticipation. Any thoughts still are appreciated.

Thanks!

---

<div class="post-metadata">

**Author:** ![dvbridges](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/dvbridges/32/1918_2.png) [@dvbridges](https://discourse.psychopy.org/u/dvbridges)\
**Post date:** [March 14, 2019, 11:28am UTC](https://discourse.psychopy.org/t/typeerror-not-supported-between-instances-of-list-and-float/7035/4 "2019-03-14T11:28:19Z")

</div>

Apologies, I had not realised you have inserted this code at the end of the routine (it must have been if RT.keys is None). So, actually, your original code was probably fine, depending on the keyboard settings. What responses are you saving? All keys, or something else? If you are saving all keys, rts are stored in a list, and so you have to get the value out of the list before making a comparison with a float:

```python
if RT.keys != None and RT.rt[-1] <= 0.15:

```

---

<div class="post-metadata">

**Author:** ![felipeviegas](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/felipeviegas/32/4793_2.png) [@felipeviegas](https://discourse.psychopy.org/u/felipeviegas)\
**Post date:** [March 14, 2019, 11:52am UTC](https://discourse.psychopy.org/t/typeerror-not-supported-between-instances-of-list-and-float/7035/5 "2019-03-14T11:52:43Z")

</div>

Hi @dvbridges, I am storing last key (is this fine, right?), so every trial has one key response saved. I have actually made the code to work with:

```auto
if RT.keys != None and RT.rt <= 0.15 :
    feed = 'Antecipada!'
elif RT.keys == None :
    feed = 'Aperte "M" ou "Z"!'
elif RT.keys == corrResp : 
    feed = 'Correta!'
elif RT.keys != corrResp: 
    feed = 'Errou!'

```

I believe it is another solution possible, isn’t it? This order of response check saves anticipated responses and dismiss the need to check if RT.rt is above 0.15 when response is correct or wrong. At least it seems to work and save fine on my tests. I will double check.

I have also managed to use this code at the valid trials to save the type of response (correct, wrong, anticipated or omitted), which will save me a lot of time at the data analysis. Very happy with this. Just added a code at the end of the routine:

```auto
Back2TrialsLoop.addData('feed',feed)

```

Thanks a lot for your answers and for enlightening me about comparing an empty list with a float.

Regards.

---

<div class="post-metadata">

**Author:** ![dvbridges](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/dvbridges/32/1918_2.png) [@dvbridges](https://discourse.psychopy.org/u/dvbridges)\
**Post date:** [March 14, 2019, 11:57am UTC](https://discourse.psychopy.org/t/typeerror-not-supported-between-instances-of-list-and-float/7035/6 "2019-03-14T11:57:53Z")

</div>

Great. Yes, there several many combinations of settings, but looks like you have it fixed 🙂
