Solved

Modifying selected column of Python 2D list

Posted on 2015-02-04
1
113 Views
Last Modified: 2015-02-16
I have a 2D list 'sorted_list' and need to modify selected elements of the list. The list consists of a variable number of sub lists, each - with 3 elements.  I need to modify the 3rd element of each sub list.  For example :

[[2, 25, 1], [1, 26, 2], [1, 27, 3], [1, 29, 4]]  .... I need to replace elements 1, 2, 3 and 4 with their corresponding names obtained by looking up a mysql table. The revised list could look something like
[[2, 25, NAME1], [1, 26, NAME2], [1, 27, NAME3], [1, 29, NAME4]]

I have made the attached Function 'convertPizzaNameCOMBO(sorted_list)' which should produce the modified list (attached). It gives however  the attached error message indicating SQL syntax problem (see attached error message)
 

The function seems to be working correctly from a looping standpoint. For example, if I replace sorted_list[][col] with 20 (which is a legitimate ID for looking up the table)  - all the targeted elements in the list will be changed to the name corresponding to 20.   So it appear to be some mysql syntax problem ?

Hopefully you can spot the error - or if my basic approach is incorrect, maybe you can point me in the right direction

Thanks
combo.jpg
ErrorMessage.jpg
0
Comment
Question by:jameskane
1 Comment
 

Accepted Solution

by:
jameskane earned 0 total points
ID: 40611803
 cursor.execute("select PizzaName from pizzafill where PizzaID=%s", (sorted_list[i][2],))

Open in new window

turns out that the sql was incorrect. FYI I have attached the correct sql.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Strings in Python are the set of characters that, once defined, cannot be changed by any other method like replace. Even if we use the replace method it still does not modify the original string that we use, but just copies the string and then modif…
Flask is a microframework for Python based on Werkzeug and Jinja 2. This requires you to have a good understanding of Python 2.7. Lets install Flask! To install Flask you can use a python repository for libraries tool called pip. Download this f…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now