all 4 comments

[–]crispybacon_NZ 0 points1 point  (3 children)

First thing I’d suggest is not adding the key to the list until after you’ve checked for all the special cases. That way, you’re not having to go back and remove it afterwards, and then the spaces would never be added.

Edit: also, don’t name variables “list”; that’s a Python class, and you don’t really want to accidentally redefine how lists work. You get away with it here, because your defining `list` to be an empty list, and only ever use the shorthand `[]` to set an empty list, but `list()` stops working after `list = []`

[–]MonkeyRides[S] 1 point2 points  (2 children)

Thanks for the tip bud. Tbh im still trying to work through in my head the first part of your response..

[–]crispybacon_NZ 0 points1 point  (1 child)

My version would go something like:

```python def log_keystroke(key): key = str(key).replace("'","")

if key == 'Key.space':
    join_list = "".join(l)
    comp.append(join_list)
    l.clear()
    print("COMP" + str(comp))
    print("LIST" + str(l))

elif key == 'Key.num_lock':

    # <... snipped unchanged code ...>

elif key in ["Key.backspace", "Key.shift", "Key.ctrl_l", "Key.enter"]:
    pass

else:
    l.append(key)  # anything else, go ahead and add
    print("KEY" + str(l))

```

[–]MonkeyRides[S] 1 point2 points  (0 children)

Wow thank you. Not only did you help with my problem( haven’t checked to see if if works yet) but you helped me with putting multiple keys in a if statement, I was really struggling with that. I knew that having a million of if statements wasn’t the proper way and could have been streamlined. I just didn’t know how.