From daniel at danielveazey.com Sat Aug 6 14:40:17 2011 From: daniel at danielveazey.com (Daniel Veazey) Date: Sat, 6 Aug 2011 07:40:17 -0500 Subject: [PyAR2] .upper() Message-ID: Almost a total noob here, getting stumped. Using Python 2.7.1+. Here is my code: while True: reply = input("Enter text: ") if reply == 'stop': break print(reply.upper()) It's supposed to just take the text that the user has entered and print it in uppercase, unless the user types 'stop.' But I get errors when I run it: Enter text: word Traceback (most recent call last): File "upper.py", line 2, in reply = input("Enter text: ") File "", line 1, in NameError: name 'word' is not defined Enter text: stop Traceback (most recent call last): File "upper.py", line 2, in reply = input("Enter text: ") File "", line 1, in NameError: name 'stop' is not defined Enter text: two words Traceback (most recent call last): File "upper.py", line 2, in reply = input("Enter text: ") File "", line 1 two words ^ SyntaxError: unexpected EOF while parsing Any tips? -------------- next part -------------- An HTML attachment was scrubbed... URL: From pyar2 at cowsgomoo.org Sat Aug 6 14:46:00 2011 From: pyar2 at cowsgomoo.org (Coltrey Mather) Date: Sat, 6 Aug 2011 07:46:00 -0500 Subject: [PyAR2] .upper() In-Reply-To: References: Message-ID: You want to use raw_input(), not input(). input() will send whatever you input to the python interpreter for evaluation and return its result. raw_input will return a string of your input. raw_input(...) raw_input([prompt]) -> string Read a string from standard input. The trailing newline is stripped. If the user hits EOF (Unix: Ctl-D, Windows: Ctl-Z+Return), raise EOFError. On Unix, GNU readline is used if enabled. The prompt string, if given, is printed without a trailing newline before reading. input(...) input([prompt]) -> value Equivalent to eval(raw_input(prompt)). On Sat, Aug 6, 2011 at 07:40, Daniel Veazey wrote: > Almost a total noob here, getting stumped. Using Python 2.7.1+. Here is my > code: > > while True: > ??? reply = input("Enter text: ") > ??? if reply == 'stop': break > ??? print(reply.upper()) > > It's supposed to just take the text that the user has entered and print it > in uppercase, unless the user types 'stop.' > > But I get errors when I run it: > > Enter text: word > Traceback (most recent call last): > ? File "upper.py", line 2, in > ??? reply = input("Enter text: ") > ? File "", line 1, in > NameError: name 'word' is not defined > > Enter text: stop > Traceback (most recent call last): > ? File "upper.py", line 2, in > ??? reply = input("Enter text: ") > ? File "", line 1, in > NameError: name 'stop' is not defined > > Enter text: two words > Traceback (most recent call last): > ? File "upper.py", line 2, in > ??? reply = input("Enter text: ") > ? File "", line 1 > ??? two words > ??????????? ^ > SyntaxError: unexpected EOF while parsing > > Any tips? > > > _______________________________________________ > PyAR2 mailing list > PyAR2 at python.org > http://mail.python.org/mailman/listinfo/pyar2 > > From ccn at panix.com Sat Aug 6 18:18:41 2011 From: ccn at panix.com (Chris Nestrud) Date: Sat, 6 Aug 2011 11:18:41 -0500 Subject: [PyAR2] .upper() In-Reply-To: References: Message-ID: <20110806161841.GE23875@panix.com> Try using raw_input instead of input. The input function expects a valid Python expression. The raw_input function is for general input. See http://docs.python.org/library/functions.html Chris On Sat, Aug 06, 2011 at 07:40:17AM -0500, Daniel Veazey wrote: > Almost a total noob here, getting stumped. Using Python 2.7.1+. Here is my > code: > > while True: > reply = input("Enter text: ") > if reply == 'stop': break > print(reply.upper()) > > It's supposed to just take the text that the user has entered and print it > in uppercase, unless the user types 'stop.' > > But I get errors when I run it: > > Enter text: word > Traceback (most recent call last): > File "upper.py", line 2, in > reply = input("Enter text: ") > File "", line 1, in > NameError: name 'word' is not defined > > Enter text: stop > Traceback (most recent call last): > File "upper.py", line 2, in > reply = input("Enter text: ") > File "", line 1, in > NameError: name 'stop' is not defined > > Enter text: two words > Traceback (most recent call last): > File "upper.py", line 2, in > reply = input("Enter text: ") > File "", line 1 > two words > ^ > SyntaxError: unexpected EOF while parsing > > Any tips? > _______________________________________________ > PyAR2 mailing list > PyAR2 at python.org > http://mail.python.org/mailman/listinfo/pyar2 From chris at jsconf.com Tue Aug 9 04:27:18 2011 From: chris at jsconf.com (Chris Williams) Date: Mon, 8 Aug 2011 22:27:18 -0400 Subject: [PyAR2] PyCodeConf is in Miami, Florida, October 6 and 7 Message-ID: Hi everyone, I am the curator of GitHub's new PyCodeConf http://py.codeconf.com happening in Miami, Florida on October 6th and 7th. This conference is a single track, intimate experience for Python developers with a deep focus on the future of the language (where it is going and why). We have gathered speakers including Audrey Roy, Alex Gaynor, Travis Oliphant, Avery Pennarun, Jesse Noller, Gary Bernhardt and many more for two days of amazing presentations. There will be at least two fully inclusive evening social events designed to give you a taste of Miami and direct access to the speakers and other attendees. PyCodeConf is being held at the luxury boutique Epic Hotel where attendees can book a room at the special rate of $179/night. The event is presented by GitHub as part of the CodeConf series, the first of which was a huge success in San Francisco. As with every CodeConf event, we believe that coding is about more than just code. Whether it's building a solid community, writing good documentation, or hacking space exploration, CodeConf is about improving the software ecosystem through best practices and social interactions. Come with an open mind and leave a better programmer. Early bird tickets have already sold out, but general admission tickets are available for $600 (includes conference and all social events). We are happy to offer you a local Python user group discount of $150 with the registration link below. If you have a long purchasing process we can hold ticket slots for you, just email us at codeconf at github.com https://eventrainbow.com/github/pycodeconf?promo=pyuser We look forward to seeing you in Miami! Chris Williams and the CodeConf Team -- Chris Williams Twitter: http://twitter.com/voodootikigod The things I make that you should check out: OurParents: http://ourparents.com PromoteJS: http://promotejs.com JSConf US: http://jsconf.us Minute With: http://minutewith.com JSConf Live: http://jsconflive.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From pythonlarry at gmail.com Mon Aug 15 15:24:36 2011 From: pythonlarry at gmail.com (Larry Hale) Date: Mon, 15 Aug 2011 08:24:36 -0500 Subject: [PyAR2] PyAR 2011 In-Reply-To: References: Message-ID: An FYI for those looking to join the pyar2-organizers mailing list: go to http://mail.python.org/mailman/listinfo + slash + "pyar2-organizers". (It seems to be an "unpublished"/"unadvertised" list. I didn't "find" the page so much as took a lucky guess. :o) [1] I would like to help however I can! [2] As for topics I'd like covered: Documentation (Sphinx) Python + SVN Integration Check-In/-Out conformity scripts, especially How to have unified code formatting on the back end, whilst allowing programmers the flexibility for however they prefer to code/view source on their end. Utilities suggested for this purpose. Python Libraries, Eggs, HOW-TO Workshop Or at least a demo of creating one, top-to-bottom. (Still seems like Magic to me, but honestly haven't tried to climb this mountain personally... partially due to my perception of Magic.) Code Testing Doctests Unittests Nose RobotTests The state of Python Web Development Top ISP's, Availability Underlying Technologies No longer mod_python, now mod_wsgi? What about mod_parrot - I know, a whole 'NOTHER kettle of fish! ;o) Basic-to-Advanced Frameworks web2py Django Solution for "a more PHP-like environment" My point: what combination/recipe would allow someone to migrate relatively easily (apart from code re-writes) from PHP to a Py platform? [3] I don't feel that _I_ am ready to _give_ any talk(s) this year, but hope to be more-able-to next! Cheers, all, and I know _I_ am looking forward to it! :D On Sat, Jul 16, 2011 at 7:29 AM, Greg Lindstrom wrote: > We are starting to plan pyAR 2011 to be held on the campus of UCA this > Fall. We are looking at Saturday, October 22 to avoid any UCA home football > games and the ACM competition on Nov 5. If you are interested in helping > organize the conference -- there is a lot to do and no experience is > required -- please sign up on the pyar2-organizers mailing list. You can do > a little or a lot; either will be appreciated. > > Traditionally, we set up classes (1 1/2 hour long) and talks (1 hour long) > on various topics. This year we plan to add a track for students to present > papers on how they use Python. This will give them an opportunity to put > together a presentation and get in front of people. What classes and/or > topics do you want to see addressed this year? Anything Python related will > be considered (last year we had a complaint that there were no Perl classes! > Go figure). Possible topics include beginning Python, intermediate Python > (what topics do you consider intermediate?), database, web, GUI, game > programming, documentation (that's me...I love Sphinx!), whatever. Please > make a suggestion or two! > > I'll post again here when we confirm the date and get speakers set up. > Again, if you want to help out, please join the organizers list. > > --greg > > _______________________________________________ > PyAR2 mailing list > PyAR2 at python.org > http://mail.python.org/mailman/listinfo/pyar2 > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From brian.curtin at gmail.com Tue Aug 16 00:51:02 2011 From: brian.curtin at gmail.com (Brian Curtin) Date: Mon, 15 Aug 2011 17:51:02 -0500 Subject: [PyAR2] Looking for PyCon 2012 Speakers Message-ID: With PyCon 2012 efforts off to a great start, we?re looking for you, the people of the Python community, to show us what you?ve got. Our call for proposals (http://us.pycon.org/2012/cfp/) just went out and we want to include you in our 2012 conference schedule, taking place March 7-15, 2012 in Santa Clara, CA. The call covers tutorial, talk, and poster applications, and we?re expecting to blow the previous record of 250 applications out of the water. Put together your best 3-hour class proposals for one of the tutorial sessions on March 7 and 8. Submit your best talks on any range of topics for the conference days, March 9 through 11. The poster session will be in full swing on Sunday with a series of 4'x4' posters and an open floor for attendees to interact with presenters. Get your applications in early - we want to help you put together the best proposal possible, so we?re going to work with submitters as applications come in. See more details and submit your talks here: http://us.pycon.org/2012/speaker/ We?re also looking for feedback from your past PyCon experiences along with what you?re looking for in the future, by way of our 2012 Guidance Survey at https://www.surveymonkey.com/s/pycon2012_launch_survey. The attendees make the conference, so every response we get from you makes a difference in putting together the best conference we can. If you or your company is interested in sponsoring PyCon, we?d love to hear from you. Join our growing list with Diamond sponsors Google and Dropbox, and Platinum sponsors Microsoft, Nasuni, SurveyMonkey, and Gondor by Eldarion. CCP Games, Linode, Walt Disney Animation Studios, Canonical, DotCloud, Loggly, Revolution Systems, ZeOmega, bitly, ActiveState, JetBrains, Snoball, Caktus Consulting Group, and Disqus make up our Gold sponsors. The Silver sponsors so far are 10gen, GitHub, Olark, Wingware, net-ng, Imaginary Landscape, BigDoor, Fwix, AG Interactive, Bitbucket, The Open Bastion, Accense Technology, Cox Media Group, and myYearbook. See our sponsorship page at http://us.pycon.org/2012/sponsors/ for more details. The PyCon Organizers - http://us.pycon.org/2012 Jesse Noller - Chairman - jnoller at python.org Brian Curtin - Publicity Coordinator - brian at python.org From daniel at danielveazey.com Sun Aug 21 16:04:34 2011 From: daniel at danielveazey.com (Daniel Veazey) Date: Sun, 21 Aug 2011 09:04:34 -0500 Subject: [PyAR2] TypeError: 'int' object is not subscriptable Message-ID: In my efforts to learn Python, I'm trying to write a program to solve a Sudoku puzzle. Here is the code I have so far: ## define and populate the board by rows; 0 = unsolved position row = [0, 1, 2, 3, 4, 5, 6, 7, 8] row[0] = [5, 6, 0, 0, 4, 1, 0, 0, 8] row[1] = [1, 0, 0, 0, 0, 9, 0, 7, 0] row[2] = [0, 8, 0, 5, 0, 2, 3, 0, 0] row[3] = [3, 0, 9, 0, 2, 0, 0, 5, 0] row[4] = [0, 7, 0, 3, 0, 5, 0, 9, 0] row[5] = [0, 5, 0, 0, 7, 0, 6, 0, 1] row[6] = [0, 0, 2, 1, 0, 3, 0, 6, 0] row[7] = [0, 3, 0, 2, 0, 0, 0, 0, 9] row[8] = [6, 0, 0, 4, 5, 0, 0, 8, 3] ## define and populate the columns by referring to the rows col = [0, 1, 2, 3, 4, 5, 6, 7, 8] col[0] = [row[0[0]], row[1[0]], row[2[0]], row[3[0]], row[4[0]], row[5[0]], row[6[0]], row[7[0]], row[8[0]]] col[1] = [row[0[1]], row[1[1]], row[2[1]], row[3[1]], row[4[1]], row[5[1]], row[6[1]], row[7[1]], row[8[1]]] col[2] = [row[0[2]], row[1[2]], row[2[2]], row[3[2]], row[4[2]], row[5[2]], row[6[2]], row[7[2]], row[8[2]]] col[3] = [row[0[3]], row[1[3]], row[2[3]], row[3[3]], row[4[3]], row[5[3]], row[6[3]], row[7[3]], row[8[3]]] col[4] = [row[0[4]], row[1[4]], row[2[4]], row[3[4]], row[4[4]], row[5[4]], row[6[4]], row[7[4]], row[8[4]]] col[5] = [row[0[5]], row[1[5]], row[2[5]], row[3[5]], row[4[5]], row[5[5]], row[6[5]], row[7[5]], row[8[5]]] col[6] = [row[0[6]], row[1[6]], row[2[6]], row[3[6]], row[4[6]], row[5[6]], row[6[6]], row[7[6]], row[8[6]]] col[7] = [row[0[7]], row[1[7]], row[2[7]], row[3[7]], row[4[7]], row[5[7]], row[6[7]], row[7[7]], row[8[7]]] col[8] = [row[0[8]], row[1[8]], row[2[8]], row[3[8]], row[4[8]], row[5[8]], row[6[8]], row[7[8]], row[8[8]]] When I run the program, the first part of defining the rows runs fine, but when I start to define the columns, I get this error: Traceback (most recent call last): File "sudoku_solver_1.py", line 15, in col[0] = [row[0[0]], row[1[0]], row[2[0]], row[3[0]], row[4[0]], row[5[0]], row[6[0]], row[7[0]], row[8[0]]] TypeError: 'int' object is not subscriptable I'm not quite sure what I'm doing wrong here. I want to nest a list inside the list col by referring to the nested lists in row. Any tips on why I'm getting this error or what I should do to fix it? Thanks, Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: From pyar2 at cowsgomoo.org Sun Aug 21 19:20:15 2011 From: pyar2 at cowsgomoo.org (Coltrey Mather) Date: Sun, 21 Aug 2011 12:20:15 -0500 Subject: [PyAR2] TypeError: 'int' object is not subscriptable In-Reply-To: References: Message-ID: Like row[0][0] instead of like row[0[0]] in all your stuff On Aug 21, 2011 9:04 AM, "Daniel Veazey" wrote: > In my efforts to learn Python, I'm trying to write a program to solve a > Sudoku puzzle. Here is the code I have so far: > > ## define and populate the board by rows; 0 = unsolved position > row = [0, 1, 2, 3, 4, 5, 6, 7, 8] > row[0] = [5, 6, 0, 0, 4, 1, 0, 0, 8] > row[1] = [1, 0, 0, 0, 0, 9, 0, 7, 0] > row[2] = [0, 8, 0, 5, 0, 2, 3, 0, 0] > row[3] = [3, 0, 9, 0, 2, 0, 0, 5, 0] > row[4] = [0, 7, 0, 3, 0, 5, 0, 9, 0] > row[5] = [0, 5, 0, 0, 7, 0, 6, 0, 1] > row[6] = [0, 0, 2, 1, 0, 3, 0, 6, 0] > row[7] = [0, 3, 0, 2, 0, 0, 0, 0, 9] > row[8] = [6, 0, 0, 4, 5, 0, 0, 8, 3] > > ## define and populate the columns by referring to the rows > col = [0, 1, 2, 3, 4, 5, 6, 7, 8] > col[0] = [row[0[0]], row[1[0]], row[2[0]], row[3[0]], row[4[0]], row[5[0]], > row[6[0]], row[7[0]], row[8[0]]] > col[1] = [row[0[1]], row[1[1]], row[2[1]], row[3[1]], row[4[1]], row[5[1]], > row[6[1]], row[7[1]], row[8[1]]] > col[2] = [row[0[2]], row[1[2]], row[2[2]], row[3[2]], row[4[2]], row[5[2]], > row[6[2]], row[7[2]], row[8[2]]] > col[3] = [row[0[3]], row[1[3]], row[2[3]], row[3[3]], row[4[3]], row[5[3]], > row[6[3]], row[7[3]], row[8[3]]] > col[4] = [row[0[4]], row[1[4]], row[2[4]], row[3[4]], row[4[4]], row[5[4]], > row[6[4]], row[7[4]], row[8[4]]] > col[5] = [row[0[5]], row[1[5]], row[2[5]], row[3[5]], row[4[5]], row[5[5]], > row[6[5]], row[7[5]], row[8[5]]] > col[6] = [row[0[6]], row[1[6]], row[2[6]], row[3[6]], row[4[6]], row[5[6]], > row[6[6]], row[7[6]], row[8[6]]] > col[7] = [row[0[7]], row[1[7]], row[2[7]], row[3[7]], row[4[7]], row[5[7]], > row[6[7]], row[7[7]], row[8[7]]] > col[8] = [row[0[8]], row[1[8]], row[2[8]], row[3[8]], row[4[8]], row[5[8]], > row[6[8]], row[7[8]], row[8[8]]] > > When I run the program, the first part of defining the rows runs fine, but > when I start to define the columns, I get this error: > > Traceback (most recent call last): > File "sudoku_solver_1.py", line 15, in > col[0] = [row[0[0]], row[1[0]], row[2[0]], row[3[0]], row[4[0]], > row[5[0]], row[6[0]], row[7[0]], row[8[0]]] > TypeError: 'int' object is not subscriptable > > I'm not quite sure what I'm doing wrong here. I want to nest a list inside > the list col by referring to the nested lists in row. Any tips on why I'm > getting this error or what I should do to fix it? > > Thanks, > Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: From dr.cburch at gmail.com Sun Aug 21 20:54:14 2011 From: dr.cburch at gmail.com (Carl Burch) Date: Sun, 21 Aug 2011 13:54:14 -0500 Subject: [PyAR2] TypeError: 'int' object is not subscriptable In-Reply-To: References: Message-ID: <53750EC0-A265-46AA-9433-1E577CC9456F@gmail.com> Yes, you access an element with r[i][j], since after all a 2d array is just the same as a list of lists; r[i] is a single one of those lists, and you'd add [j] to extract an element from that list. To go further beyond what you ask: It's also interesting how you can do the same thing with list comprehensions: col[0] = [r[0] for r in row] Here, r iterates through each row in the row array, and we build up an array of all the r[0]'s. You could repeat this same line 8 more times, but I'd put it into a loop: for i in range(9): col[i] = [r[i] for r in row] Or we could even nest the comprehension into another comprehension: col = [[r[i] for r in row] for i in range(9)] Maybe somebody else has an even cleverer way to build up the translation of a 2d array. -Carl On Aug 21, 2011, at 12:20 PM, Coltrey Mather wrote: > Like row[0][0] instead of like row[0[0]] in all your stuff > > On Aug 21, 2011 9:04 AM, "Daniel Veazey" wrote: > > In my efforts to learn Python, I'm trying to write a program to solve a > > Sudoku puzzle. Here is the code I have so far: > > > > ## define and populate the board by rows; 0 = unsolved position > > row = [0, 1, 2, 3, 4, 5, 6, 7, 8] > > row[0] = [5, 6, 0, 0, 4, 1, 0, 0, 8] > > row[1] = [1, 0, 0, 0, 0, 9, 0, 7, 0] > > row[2] = [0, 8, 0, 5, 0, 2, 3, 0, 0] > > row[3] = [3, 0, 9, 0, 2, 0, 0, 5, 0] > > row[4] = [0, 7, 0, 3, 0, 5, 0, 9, 0] > > row[5] = [0, 5, 0, 0, 7, 0, 6, 0, 1] > > row[6] = [0, 0, 2, 1, 0, 3, 0, 6, 0] > > row[7] = [0, 3, 0, 2, 0, 0, 0, 0, 9] > > row[8] = [6, 0, 0, 4, 5, 0, 0, 8, 3] > > > > ## define and populate the columns by referring to the rows > > col = [0, 1, 2, 3, 4, 5, 6, 7, 8] > > col[0] = [row[0[0]], row[1[0]], row[2[0]], row[3[0]], row[4[0]], row[5[0]], > > row[6[0]], row[7[0]], row[8[0]]] > > col[1] = [row[0[1]], row[1[1]], row[2[1]], row[3[1]], row[4[1]], row[5[1]], > > row[6[1]], row[7[1]], row[8[1]]] > > col[2] = [row[0[2]], row[1[2]], row[2[2]], row[3[2]], row[4[2]], row[5[2]], > > row[6[2]], row[7[2]], row[8[2]]] > > col[3] = [row[0[3]], row[1[3]], row[2[3]], row[3[3]], row[4[3]], row[5[3]], > > row[6[3]], row[7[3]], row[8[3]]] > > col[4] = [row[0[4]], row[1[4]], row[2[4]], row[3[4]], row[4[4]], row[5[4]], > > row[6[4]], row[7[4]], row[8[4]]] > > col[5] = [row[0[5]], row[1[5]], row[2[5]], row[3[5]], row[4[5]], row[5[5]], > > row[6[5]], row[7[5]], row[8[5]]] > > col[6] = [row[0[6]], row[1[6]], row[2[6]], row[3[6]], row[4[6]], row[5[6]], > > row[6[6]], row[7[6]], row[8[6]]] > > col[7] = [row[0[7]], row[1[7]], row[2[7]], row[3[7]], row[4[7]], row[5[7]], > > row[6[7]], row[7[7]], row[8[7]]] > > col[8] = [row[0[8]], row[1[8]], row[2[8]], row[3[8]], row[4[8]], row[5[8]], > > row[6[8]], row[7[8]], row[8[8]]] > > > > When I run the program, the first part of defining the rows runs fine, but > > when I start to define the columns, I get this error: > > > > Traceback (most recent call last): > > File "sudoku_solver_1.py", line 15, in > > col[0] = [row[0[0]], row[1[0]], row[2[0]], row[3[0]], row[4[0]], > > row[5[0]], row[6[0]], row[7[0]], row[8[0]]] > > TypeError: 'int' object is not subscriptable > > > > I'm not quite sure what I'm doing wrong here. I want to nest a list inside > > the list col by referring to the nested lists in row. Any tips on why I'm > > getting this error or what I should do to fix it? > > > > Thanks, > > Daniel > _______________________________________________ > PyAR2 mailing list > PyAR2 at python.org > http://mail.python.org/mailman/listinfo/pyar2 -------------- next part -------------- An HTML attachment was scrubbed... URL: From rob at robnet.com Mon Aug 22 16:34:21 2011 From: rob at robnet.com (Rob Nichols) Date: Mon, 22 Aug 2011 09:34:21 -0500 Subject: [PyAR2] TypeError: 'int' object is not subscriptable In-Reply-To: <53750EC0-A265-46AA-9433-1E577CC9456F@gmail.com> References: <53750EC0-A265-46AA-9433-1E577CC9456F@gmail.com> Message-ID: <53820F06-32ED-46C5-9152-1AC9094FA929@robnet.com> This is a little off topic and you probably already have something similar, but this site has a bunch of puzzles that can be handy for testing your resulting program. (At least, that's how I tested mine? :-) On Aug 21, 2011, at 1:54 PM, Carl Burch wrote: > Yes, you access an element with r[i][j], since after all a 2d array is just the same as a list of lists; r[i] is a single one of those lists, and you'd add [j] to extract an element from that list. > > To go further beyond what you ask: It's also interesting how you can do the same thing with list comprehensions: > > col[0] = [r[0] for r in row] > > Here, r iterates through each row in the row array, and we build up an array of all the r[0]'s. > > You could repeat this same line 8 more times, but I'd put it into a loop: > > for i in range(9): > col[i] = [r[i] for r in row] > > Or we could even nest the comprehension into another comprehension: > > col = [[r[i] for r in row] for i in range(9)] > > Maybe somebody else has an even cleverer way to build up the translation of a 2d array. > > -Carl > > On Aug 21, 2011, at 12:20 PM, Coltrey Mather wrote: > >> Like row[0][0] instead of like row[0[0]] in all your stuff >> >> On Aug 21, 2011 9:04 AM, "Daniel Veazey" wrote: >> > In my efforts to learn Python, I'm trying to write a program to solve a >> > Sudoku puzzle. Here is the code I have so far: >> > >> > ## define and populate the board by rows; 0 = unsolved position >> > row = [0, 1, 2, 3, 4, 5, 6, 7, 8] >> > row[0] = [5, 6, 0, 0, 4, 1, 0, 0, 8] >> > row[1] = [1, 0, 0, 0, 0, 9, 0, 7, 0] >> > row[2] = [0, 8, 0, 5, 0, 2, 3, 0, 0] >> > row[3] = [3, 0, 9, 0, 2, 0, 0, 5, 0] >> > row[4] = [0, 7, 0, 3, 0, 5, 0, 9, 0] >> > row[5] = [0, 5, 0, 0, 7, 0, 6, 0, 1] >> > row[6] = [0, 0, 2, 1, 0, 3, 0, 6, 0] >> > row[7] = [0, 3, 0, 2, 0, 0, 0, 0, 9] >> > row[8] = [6, 0, 0, 4, 5, 0, 0, 8, 3] >> > >> > ## define and populate the columns by referring to the rows >> > col = [0, 1, 2, 3, 4, 5, 6, 7, 8] >> > col[0] = [row[0[0]], row[1[0]], row[2[0]], row[3[0]], row[4[0]], row[5[0]], >> > row[6[0]], row[7[0]], row[8[0]]] >> > col[1] = [row[0[1]], row[1[1]], row[2[1]], row[3[1]], row[4[1]], row[5[1]], >> > row[6[1]], row[7[1]], row[8[1]]] >> > col[2] = [row[0[2]], row[1[2]], row[2[2]], row[3[2]], row[4[2]], row[5[2]], >> > row[6[2]], row[7[2]], row[8[2]]] >> > col[3] = [row[0[3]], row[1[3]], row[2[3]], row[3[3]], row[4[3]], row[5[3]], >> > row[6[3]], row[7[3]], row[8[3]]] >> > col[4] = [row[0[4]], row[1[4]], row[2[4]], row[3[4]], row[4[4]], row[5[4]], >> > row[6[4]], row[7[4]], row[8[4]]] >> > col[5] = [row[0[5]], row[1[5]], row[2[5]], row[3[5]], row[4[5]], row[5[5]], >> > row[6[5]], row[7[5]], row[8[5]]] >> > col[6] = [row[0[6]], row[1[6]], row[2[6]], row[3[6]], row[4[6]], row[5[6]], >> > row[6[6]], row[7[6]], row[8[6]]] >> > col[7] = [row[0[7]], row[1[7]], row[2[7]], row[3[7]], row[4[7]], row[5[7]], >> > row[6[7]], row[7[7]], row[8[7]]] >> > col[8] = [row[0[8]], row[1[8]], row[2[8]], row[3[8]], row[4[8]], row[5[8]], >> > row[6[8]], row[7[8]], row[8[8]]] >> > >> > When I run the program, the first part of defining the rows runs fine, but >> > when I start to define the columns, I get this error: >> > >> > Traceback (most recent call last): >> > File "sudoku_solver_1.py", line 15, in >> > col[0] = [row[0[0]], row[1[0]], row[2[0]], row[3[0]], row[4[0]], >> > row[5[0]], row[6[0]], row[7[0]], row[8[0]]] >> > TypeError: 'int' object is not subscriptable >> > >> > I'm not quite sure what I'm doing wrong here. I want to nest a list inside >> > the list col by referring to the nested lists in row. Any tips on why I'm >> > getting this error or what I should do to fix it? >> > >> > Thanks, >> > Daniel >> _______________________________________________ >> PyAR2 mailing list >> PyAR2 at python.org >> http://mail.python.org/mailman/listinfo/pyar2 > _______________________________________________ > PyAR2 mailing list > PyAR2 at python.org > http://mail.python.org/mailman/listinfo/pyar2 -------------- next part -------------- An HTML attachment was scrubbed... URL: From daniel at danielveazey.com Mon Aug 22 22:43:39 2011 From: daniel at danielveazey.com (Daniel Veazey) Date: Mon, 22 Aug 2011 15:43:39 -0500 Subject: [PyAR2] TypeError: 'int' object is not subscriptable In-Reply-To: <53750EC0-A265-46AA-9433-1E577CC9456F@gmail.com> References: <53750EC0-A265-46AA-9433-1E577CC9456F@gmail.com> Message-ID: Thanks for your comments and help. I have finished the first version of the program, and here is a link to the code: http://paste.ubuntu.com/672710/ It only uses the most basic of methods to solve puzzles, so even some puzzles rated as "easy" still stump it. But it does what I set out for it to do, and I'm proud of that. I plan to incorporate more advanced methods to solve harder puzzles later. I learned a lot doing this. Thanks again for the help. If you want to try it out, I'd appreciate any feedback. Thanks, Daniel On Sun, Aug 21, 2011 at 1:54 PM, Carl Burch wrote: > Yes, you access an element with r[i][j], since after all a 2d array is just > the same as a list of lists; r[i] is a single one of those lists, and you'd > add [j] to extract an element from that list. > > To go further beyond what you ask: It's also interesting how you can do the > same thing with list comprehensions: > > col[0] = [r[0] for r in row] > > Here, r iterates through each row in the row array, and we build up an > array of all the r[0]'s. > > You could repeat this same line 8 more times, but I'd put it into a loop: > > for i in range(9): > col[i] = [r[i] for r in row] > > Or we could even nest the comprehension into another comprehension: > > col = [[r[i] for r in row] for i in range(9)] > > Maybe somebody else has an even cleverer way to build up the translation of > a 2d array. > > -Carl > > On Aug 21, 2011, at 12:20 PM, Coltrey Mather wrote: > > Like row[0][0] instead of like row[0[0]] in all your stuff > On Aug 21, 2011 9:04 AM, "Daniel Veazey" < > daniel at danielveazey.com> wrote: > > In my efforts to learn Python, I'm trying to write a program to solve a > > Sudoku puzzle. Here is the code I have so far: > > > > ## define and populate the board by rows; 0 = unsolved position > > row = [0, 1, 2, 3, 4, 5, 6, 7, 8] > > row[0] = [5, 6, 0, 0, 4, 1, 0, 0, 8] > > row[1] = [1, 0, 0, 0, 0, 9, 0, 7, 0] > > row[2] = [0, 8, 0, 5, 0, 2, 3, 0, 0] > > row[3] = [3, 0, 9, 0, 2, 0, 0, 5, 0] > > row[4] = [0, 7, 0, 3, 0, 5, 0, 9, 0] > > row[5] = [0, 5, 0, 0, 7, 0, 6, 0, 1] > > row[6] = [0, 0, 2, 1, 0, 3, 0, 6, 0] > > row[7] = [0, 3, 0, 2, 0, 0, 0, 0, 9] > > row[8] = [6, 0, 0, 4, 5, 0, 0, 8, 3] > > > > ## define and populate the columns by referring to the rows > > col = [0, 1, 2, 3, 4, 5, 6, 7, 8] > > col[0] = [row[0[0]], row[1[0]], row[2[0]], row[3[0]], row[4[0]], > row[5[0]], > > row[6[0]], row[7[0]], row[8[0]]] > > col[1] = [row[0[1]], row[1[1]], row[2[1]], row[3[1]], row[4[1]], > row[5[1]], > > row[6[1]], row[7[1]], row[8[1]]] > > col[2] = [row[0[2]], row[1[2]], row[2[2]], row[3[2]], row[4[2]], > row[5[2]], > > row[6[2]], row[7[2]], row[8[2]]] > > col[3] = [row[0[3]], row[1[3]], row[2[3]], row[3[3]], row[4[3]], > row[5[3]], > > row[6[3]], row[7[3]], row[8[3]]] > > col[4] = [row[0[4]], row[1[4]], row[2[4]], row[3[4]], row[4[4]], > row[5[4]], > > row[6[4]], row[7[4]], row[8[4]]] > > col[5] = [row[0[5]], row[1[5]], row[2[5]], row[3[5]], row[4[5]], > row[5[5]], > > row[6[5]], row[7[5]], row[8[5]]] > > col[6] = [row[0[6]], row[1[6]], row[2[6]], row[3[6]], row[4[6]], > row[5[6]], > > row[6[6]], row[7[6]], row[8[6]]] > > col[7] = [row[0[7]], row[1[7]], row[2[7]], row[3[7]], row[4[7]], > row[5[7]], > > row[6[7]], row[7[7]], row[8[7]]] > > col[8] = [row[0[8]], row[1[8]], row[2[8]], row[3[8]], row[4[8]], > row[5[8]], > > row[6[8]], row[7[8]], row[8[8]]] > > > > When I run the program, the first part of defining the rows runs fine, > but > > when I start to define the columns, I get this error: > > > > Traceback (most recent call last): > > File "sudoku_solver_1.py", line 15, in > > col[0] = [row[0[0]], row[1[0]], row[2[0]], row[3[0]], row[4[0]], > > row[5[0]], row[6[0]], row[7[0]], row[8[0]]] > > TypeError: 'int' object is not subscriptable > > > > I'm not quite sure what I'm doing wrong here. I want to nest a list > inside > > the list col by referring to the nested lists in row. Any tips on why I'm > > getting this error or what I should do to fix it? > > > > Thanks, > > Daniel > > _______________________________________________ > PyAR2 mailing list > PyAR2 at python.org > http://mail.python.org/mailman/listinfo/pyar2 > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gslindstrom at gmail.com Sat Aug 27 15:15:46 2011 From: gslindstrom at gmail.com (Greg Lindstrom) Date: Sat, 27 Aug 2011 08:15:46 -0500 Subject: [PyAR2] pyArkasas 2011 - Call For Papers Message-ID: Plans for pyArkansas 2011 are underway. The 4th annual Python conference will be held October 22 on the campus of UCA (Computer Science Department) and this year we would like *you* to present a talk on what you are doing with Python. Talks are 50 minutes (40 minutes of you talking and then 10-minutes for questions) and can be on anything Python. Are you using a standard library module that's really cool? Perhaps a third party package that you think other people should know about? What about that killer project where you did something interesting or fun using Python? This is a chance for you to share your knowledge with an audience that wants to hear what you have to say! Don't think you have to be a "Python Heavyweight" to present; if you are doing something interesting, we want to hear from you (and we're bringing in a couple of heavyweights to give tutorials and talks of their own). We want a wide selection of topics and skill levels for the conference. Do you have a paper you would like to present? This year, we have a special track for students (High School and College/University) to present academic papers (25-minute slots). How cool is that? Without talks, there is no pyArkansas. You don't want that, do you? If you are interested, please email the following information to pyar2-organizers at python.org (don't "reply" to this). - Talk Title - A brief (a paragraph or two) description of your talk - Intended audience (beginner, intermediate, advanced, web developer, gamer, astronomer, etc.) - A brief blurb about you (that we can put on the website) - Length (papers are 25-minutes, talks are 50-minutes. There are a few longer talks slots available if you feel you need a little more time) We'll look them all over and make the selections by October 1 to give you time to prepare. We're looking forward to seeing you speak this year! -------------- next part -------------- An HTML attachment was scrubbed... URL: