Creates MTG deck
This file contains 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
import re | |
CARDLIST = open('deck','r') | |
""" | |
opens a text file with a list of cards and quantities formatted as such: | |
22 ISLAND | |
47 ORNITHOPTER etc.. | |
""" | |
raw_deck = [] ##this list will hold the raw quantity/card name data eg: 22 ISLAND | |
deck = [] ##this will be the finalized version of the deck with 47 instances of ornithopter | |
for i in CARDLIST: ##append quantity/cardname to raw deck sans newline characters | |
raw_deck.append(i[0:-1]) | |
def find_card_quantity(raw_deck,deck,card): ##function that separates quantity from card name | |
re.search(([\d]+)\s([\w\s]+),raw_deck) ##and appends that to the deck list | |
card_quantity = match.group(1) | |
card_name = match.group(3) | |
for i in card_quantity: | |
deck.append(card_name) | |
for card in raw_deck: ##cycles through raw_deck, cleaning up the format | |
find_card_quantity(raw_deck,deck,card) ##and adding the correct quantities to the finished deck |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment