Python Forum
Thread Rating:
  • 2 Vote(s) - 1.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List logic
#11
so here is another one... how do I get the \ in invalidChars list without it showing up as double \\

def getUserInfo():

    while True:
        print('Enter a valid username: ')
        username = input()
        invalidChars = '!@#$%^&*()+=~`{}|[]:;"<,.>/ ?\\'
        invalidList = []
        for l in invalidChars:
            invalidList.append(l)

        print(invalidList)
        break
getUserInfo()
Output:
Enter a valid username: f ['!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '+', '=', '~', '`', '{', '}', '|', '[', ']', ':', ';', '"', '<', ',', '.', '>', '/', ' ', '?', '\\']
Reply
#12
for chars in list(zip(*grid[::-1])):
    print(''.join(chars))
Output:
..OO.OO.. .OOOOOOO. .OOOOOOO. ..OOOOO.. ...OOO... ....O....
I was lazy and found how to rotate the matrix on SO. :-)
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#13
(Apr-23-2017, 04:21 AM)wavic Wrote:
for chars in list(zip(*grid[::-1])):
    print(''.join(chars))
Output:
..OO.OO.. .OOOOOOO. .OOOOOOO. ..OOOOO.. ...OOO... ....O....
I was lazy and found how to rotate the matrix on SO. :-)

NIIIIOCCCCEEEE dudeeee :D haha thanks :P

I've played with this until my brain aches... i know im missing something simple... can someone please help. I'm just trying to compare the username to characters in the invalidList to make sure no illegal characters are allowed in a username:

def getUserInfo():

    while True:
        print('Enter a valid username: ')
        username = input().lower()
        invalidChars = '!@#$%^&*()+=~`{}|[]:;"<,.>/ ?\\'
        invalidList = []
        for l in invalidChars:
            invalidList.append(l)

        for x in username.split():
            for j in x:
                if j in invalidList:
                    print('oops')
                else:
                    break

        if any([x in invalidList for x in list(username)]):
            print('oops')
        else:
            break
Am i close? lol...

Ahhh... There it is:

        for x in list(username):
            if x in invalidList:
                print('oops')
Reply


Forum Jump:

User Panel Messages

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