Last active
February 4, 2019 01:37
-
-
Save Pinacolada64/8cb4c8aaba473c3a266d410c4086cc10 to your computer and use it in GitHub Desktop.
Understanding lists and dicts in Python3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string = "wELCOME tO cOMMODOREsERVER" # PETSCII has case reversed compared to ASCII | |
print("PETSCII: ", (string)) | |
print(" ASCII: ", string.swapcase()) # "translate" PETSCII to ASCII | |
print("") # blank line | |
# '/roominfo' csip command displays verbose info about room | |
# '/rooms' csip command lists "'room_name' ['user_count']" | |
room_names = {'lOBBY', 'C64', 'C128', 'vIC-20', 'aMIGA', 'TED', 'PET', 'SANDBOX'} | |
user_count = (0, 5, 0, 0, 0, 0, 0, 0) | |
# user_names dict is mutable | |
# 1: always present | |
# 1234: the bot | |
user_names = {1: 'rOOM', | |
1234: 'aRDIE', | |
12345: 'pINACOLADA', | |
54321: 'gOOG', | |
65535: 'aGENTfRIDAY'} | |
# TODO: creating a player ignore list might be cool | |
# TODO: usability feature: users should not have to know or type user ids to | |
# interact with a user. make a cursor-driven menu list of users somehow | |
# (at the very least, a numbered list to start with), e.g.: | |
# 1. Pinacolada | |
# 2. Goog | |
# 3. AgentFriday | |
# Which user? 2 | |
# Private messaging Goog... | |
# rooms have a room/channel id also, i believe | |
# There are list.append and list.delete methods, | |
# so if a user enters or leaves a room, can .append or .delete the user id, | |
# which would map to a user name in some other function... | |
users_in_room = (1, 1234, 12345, 54321, 65535) | |
# def user_remove_from_room(id_to_remove): | |
# ''' | |
# Remove user from list of users in room | |
# user could have disconnected or changed rooms | |
# ''' | |
# | |
# try [...] # if user exists | |
# except [...] # if user does not exist | |
# print("[%s has left the room]", user_names(id_to_remove)) | |
# users_in_room.delete(id_to_remove) | |
print("Users\tRoom name") | |
for u, r in zip(user_count, room_names): | |
print(u, "\t", r.swapcase()) | |
print("") | |
print("List users in room:") | |
print("ID\tUser name") | |
for u in users_in_room: | |
print(u, "\t", user_names[u].swapcase() ) | |
# id user name | |
# 1 Room | |
# 54321 Pinacolada | |
# 12345 Goog | |
# 65535 AgentFriday |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment