Skip to content

Instantly share code, notes, and snippets.

@borensoren
Created July 18, 2012 16:04
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save borensoren/3137158 to your computer and use it in GitHub Desktop.
Creates MTG deck
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