{"id":1512,"date":"2025-06-04T07:11:25","date_gmt":"2025-06-04T07:11:25","guid":{"rendered":"https:\/\/learnlearn.uk\/python\/?page_id=1512"},"modified":"2025-06-05T09:45:42","modified_gmt":"2025-06-05T09:45:42","slug":"python-tables","status":"publish","type":"page","link":"https:\/\/learnlearn.uk\/python\/python-tables\/","title":{"rendered":"Python Tables"},"content":{"rendered":"<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">Introduction<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Introduction<\/h3>\n<p data-start=\"116\" data-end=\"446\">In programming, a <strong data-start=\"134\" data-end=\"143\">table<\/strong> is a structured way to organize and display data in rows and columns\u2014just like a spreadsheet. Python doesn\u2019t have a built-in table data structure, but you can easily create and work with tables using lists, dictionaries, or third-party libraries like <strong data-start=\"395\" data-end=\"407\"><code data-start=\"397\" data-end=\"405\">pandas<\/code><\/strong>, <strong data-start=\"409\" data-end=\"423\"><code data-start=\"411\" data-end=\"421\">tabulate<\/code><\/strong>, or <strong data-start=\"428\" data-end=\"445\"><code data-start=\"430\" data-end=\"443\">PrettyTable<\/code><\/strong>.<\/p>\n<p data-start=\"448\" data-end=\"573\">A <strong data-start=\"450\" data-end=\"465\">basic table<\/strong> in Python is often represented as a list of lists (for rows) or a list of dictionaries (for named columns).<\/p>\n<h4 data-start=\"575\" data-end=\"604\">Example (List of Lists):<\/h4>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"whitespace-pre! language-python\"><span class=\"hljs-comment\"># Headers<\/span><br \/>\nheaders = [<span class=\"hljs-string\">\"Name\"<\/span>, <span class=\"hljs-string\">\"Age\"<\/span>, <span class=\"hljs-string\">\"Grade\"<\/span>, <span class=\"hljs-string\">\"Passed\"<\/span>]<br \/>\n<\/code><\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"whitespace-pre! language-python\"><span class=\"hljs-comment\"># Rows<\/span><br \/>\nrows = [<br \/>\n[<span class=\"hljs-string\">\"Alice\"<\/span>, <span class=\"hljs-number\">14<\/span>, <span class=\"hljs-string\">\"A\"<\/span>, <span class=\"hljs-string\">\"Yes\"<\/span>],<br \/>\n[<span class=\"hljs-string\">\"Bob\"<\/span>, <span class=\"hljs-number\">15<\/span>, <span class=\"hljs-string\">\"B\"<\/span>, <span class=\"hljs-string\">\"Yes\"<\/span>],<br \/>\n[<span class=\"hljs-string\">\"Charlie\"<\/span>, <span class=\"hljs-number\">13<\/span>, <span class=\"hljs-string\">\"C\"<\/span>, <span class=\"hljs-string\">\"No\"<\/span>]<br \/>\n]<br \/>\n<\/code><\/div>\n<\/div>\n<p data-start=\"785\" data-end=\"867\">This format allows us to print, sort, or manipulate tabular data programmatically.<\/p>\n<p data-start=\"785\" data-end=\"867\">\n<\/div><h2 class=\"tabtitle\">Advantages<\/h2>\n<div class=\"tabcontent\">\n<\/p>\n<h3 data-start=\"785\" data-end=\"867\">Why Are Tables Useful?<\/h3>\n<ol data-start=\"904\" data-end=\"1631\">\n<li data-start=\"904\" data-end=\"1050\">\n<p data-start=\"907\" data-end=\"1050\"><strong data-start=\"907\" data-end=\"932\">Organize Data Clearly<\/strong><br data-start=\"932\" data-end=\"935\" \/>Tables provide a clean, readable way to represent structured data, making it easier to understand and work with.<\/p>\n<\/li>\n<li data-start=\"1052\" data-end=\"1194\">\n<p data-start=\"1055\" data-end=\"1194\"><strong data-start=\"1055\" data-end=\"1079\">Enable Data Analysis<\/strong><br data-start=\"1079\" data-end=\"1082\" \/>Tabular structures are essential in data analysis, where rows represent records and columns represent fields.<\/p>\n<\/li>\n<li data-start=\"1196\" data-end=\"1325\">\n<p data-start=\"1199\" data-end=\"1325\"><strong data-start=\"1199\" data-end=\"1235\">Support Iteration and Automation<\/strong><br data-start=\"1235\" data-end=\"1238\" \/>Tables make it easy to loop through and process data row-by-row or column-by-column.<\/p>\n<\/li>\n<li data-start=\"1327\" data-end=\"1499\">\n<p data-start=\"1330\" data-end=\"1499\"><strong data-start=\"1330\" data-end=\"1374\">Foundational for CSV and Excel Workflows<\/strong><br data-start=\"1374\" data-end=\"1377\" \/>Tables are the core structure used in CSV and Excel files\u2014both of which are commonly used for storing and sharing data.<\/p>\n<\/li>\n<li data-start=\"1501\" data-end=\"1631\">\n<p data-start=\"1504\" data-end=\"1631\"><strong data-start=\"1504\" data-end=\"1526\">Useful for Display<\/strong><br data-start=\"1526\" data-end=\"1529\" \/>When printing data in reports, logs, or terminal UIs, tables make the output neat and easy to read.<\/p>\n<\/li>\n<\/ol>\n\n<\/div><h2 class=\"tabtitle\">Python Code<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Python Table Example Code<\/h3>\n<pre class=\"language-javascript line-numbers\"><code class=\"language-javascript\"># Define headers and rows\r\nheaders <span class=\"token operator\">=<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token string\">\"Name\"<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">\"Age\"<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">\"Grade\"<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">\"Passed\"<\/span><span class=\"token punctuation\">]<\/span>\r\nrows <span class=\"token operator\">=<\/span> <span class=\"token punctuation\">[<\/span>\r\n    <span class=\"token punctuation\">[<\/span><span class=\"token string\">\"Alice\"<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">14<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">\"A\"<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">\"Yes\"<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span>\r\n    <span class=\"token punctuation\">[<\/span><span class=\"token string\">\"Bob\"<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">15<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">\"B\"<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">\"Yes\"<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span>\r\n    <span class=\"token punctuation\">[<\/span><span class=\"token string\">\"Charlie\"<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">13<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">\"C\"<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">\"No\"<\/span><span class=\"token punctuation\">]<\/span>\r\n<span class=\"token punctuation\">]<\/span>\r\n\r\n# Print headers using f<span class=\"token operator\">-<\/span>string\r\n<span class=\"token function\">print<\/span><span class=\"token punctuation\">(<\/span>f<span class=\"token string\">\"{headers[0]:&lt;10} {headers[1]:&lt;5} {headers[2]:&lt;7} {headers[3]:&lt;7}\"<\/span><span class=\"token punctuation\">)<\/span>\r\n\r\n# Print separator line\r\n<span class=\"token function\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">\"-\"<\/span> <span class=\"token operator\">*<\/span> <span class=\"token number\">35<\/span><span class=\"token punctuation\">)<\/span>\r\n\r\n# Print each row using f<span class=\"token operator\">-<\/span>string\r\n<span class=\"token keyword\">for<\/span> row <span class=\"token keyword\">in<\/span> <span class=\"token literal-property property\">rows<\/span><span class=\"token operator\">:<\/span>\r\n    <span class=\"token function\">print<\/span><span class=\"token punctuation\">(<\/span>f<span class=\"token string\">\"{row[0]:&lt;10} {row[1]:&lt;5} {row[2]:&lt;7} {row[3]:&lt;7}\"<\/span><span class=\"token punctuation\">)<\/span>\r\n<span class=\"token literal-property property\">Output<\/span><span class=\"token operator\">:<\/span>\r\nmarkdown\r\nCopy\r\nEdit\r\nName       Age   Grade   Passed \r\n<span class=\"token operator\">--<\/span><span class=\"token operator\">--<\/span><span class=\"token operator\">--<\/span><span class=\"token operator\">--<\/span><span class=\"token operator\">--<\/span><span class=\"token operator\">--<\/span><span class=\"token operator\">--<\/span><span class=\"token operator\">--<\/span><span class=\"token operator\">--<\/span><span class=\"token operator\">--<\/span><span class=\"token operator\">--<\/span><span class=\"token operator\">--<\/span><span class=\"token operator\">--<\/span><span class=\"token operator\">--<\/span><span class=\"token operator\">--<\/span><span class=\"token operator\">--<\/span><span class=\"token operator\">--<\/span><span class=\"token operator\">-<\/span>\r\nAlice      <span class=\"token number\">14<\/span>    <span class=\"token constant\">A<\/span>       Yes    \r\nBob        <span class=\"token number\">15<\/span>    <span class=\"token constant\">B<\/span>       Yes    \r\nCharlie    <span class=\"token number\">13<\/span>    <span class=\"token constant\">C<\/span>       No     <\/code><\/pre>\n<h3>Key concepts<\/h3>\n<p>&#8220;{:&lt;10}&#8221; means left-align in a space of 10 characters.<\/p>\n<p>*headers and *row unpacks the list into arguments for .format().<\/p>\n\n<\/div><h2 class=\"tabtitle\">Tutorial Video<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Tutorial Video<\/h3>\n<div class=\"nv-iframe-embed\">\n<div class=\"container-lazyload preview-lazyload container-youtube js-lazyload--not-loaded\"><a href=\"https:\/\/www.youtube.com\/watch?v=RvqmZLuCQrw\" class=\"lazy-load-youtube preview-lazyload preview-youtube\" data-video-title=\"Python  Tables Easy Tutorial\" title=\"Play video &quot;Python  Tables Easy Tutorial&quot;\">https:\/\/www.youtube.com\/watch?v=RvqmZLuCQrw<\/a><noscript>Video can&#8217;t be loaded because JavaScript is disabled: <a href=\"https:\/\/www.youtube.com\/watch?v=RvqmZLuCQrw\" title=\"Python  Tables Easy Tutorial\">Python  Tables Easy Tutorial (https:\/\/www.youtube.com\/watch?v=RvqmZLuCQrw)<\/a><\/noscript><\/div>\n<\/div>\n\n<\/div><h2 class=\"tabtitle\">Sample Table<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Sample Table<\/h3>\n<p>Here is a sample table in 2D python format for testing with the challenges. You can also use the <a href=\"http:\/\/revise.learnlearn.uk\/static\/csv_files\/MOCK_DATA%20(2).csv\">CSV file here<\/a><\/p>\n<pre>user_data = [\r\n[\"id\", \"first_name\", \"last_name\", \"email\", \"gender\", \"city\"],\r\n[\"1\", \"Morty\", \"Petrina\", \"mpetrina0@parallels.com\", \"Male\", \"H\u00f8nefoss\"],\r\n[\"2\", \"Jacquie\", \"Falkingham\", \"jfalkingham1@usgs.gov\", \"Female\", \"Stockholm\"],\r\n[\"3\", \"Marcelle\", \"Balm\", \"mbalm2@rediff.com\", \"Female\", \"Houping\"],\r\n[\"4\", \"Raviv\", \"Foulgham\", \"rfoulgham3@chron.com\", \"Male\", \"Otuzco\"],\r\n[\"5\", \"Farlay\", \"Peer\", \"fpeer4@about.me\", \"Male\", \"Huayacundo Arma\"],\r\n[\"6\", \"Edd\", \"Siemons\", \"esiemons5@wix.com\", \"Male\", \"\u017babno\"],\r\n[\"7\", \"Willdon\", \"Peetermann\", \"wpeetermann6@rakuten.co.jp\", \"Male\", \"B\u00e5stad\"],\r\n[\"8\", \"Stacie\", \"Belward\", \"sbelward7@elpais.com\", \"Female\", \"Valen\u00e7a do Douro\"],\r\n[\"9\", \"Cherry\", \"Farnin\", \"cfarnin8@spotify.com\", \"Female\", \"Curridabat\"],\r\n[\"10\", \"Odessa\", \"Thurston\", \"othurston9@xinhuanet.com\", \"Female\", \"Asunci\u00f3n Mita\"],\r\n[\"11\", \"Walsh\", \"Gaythwaite\", \"wgaythwaitea@addtoany.com\", \"Male\", \"Bordeaux\"],\r\n[\"12\", \"Effie\", \"Holehouse\", \"eholehouseb@constantcontact.com\", \"Female\", \"Colcabamba\"],\r\n[\"13\", \"Sebastian\", \"Lockley\", \"slockleyc@purevolume.com\", \"Male\", \"Comagascas\"],\r\n[\"14\", \"Danya\", \"Chambers\", \"dchambersd@drupal.org\", \"Female\", \"Jana\u00faba\"],\r\n[\"15\", \"Renado\", \"Klemensiewicz\", \"rklemensiewicze@arstechnica.com\", \"Male\", \"Oyem\"],\r\n[\"16\", \"Hadleigh\", \"Ashbee\", \"hashbeef@exblog.jp\", \"Male\", \"Ravne\"],\r\n[\"17\", \"Faythe\", \"Brimfield\", \"fbrimfieldg@mac.com\", \"Female\", \"P\u00f5lva\"],\r\n[\"18\", \"Temp\", \"Cowerd\", \"tcowerdh@msu.edu\", \"Male\", \"Eisen\"],\r\n[\"19\", \"Enrichetta\", \"Delamar\", \"edelamari@pen.io\", \"Female\", \"Charleston\"],\r\n[\"20\", \"Justus\", \"Leteurtre\", \"jleteurtrej@yahoo.com\", \"Male\", \"Rio de Moinhos\"],\r\n[\"21\", \"Salaidh\", \"Escalera\", \"sescalerak@youtube.com\", \"Female\", \"Bantarjati\"],\r\n[\"22\", \"Rachael\", \"Coneybeer\", \"rconeybeerl@ft.com\", \"Female\", \"Glencoe\"],\r\n[\"23\", \"Lenard\", \"Wykey\", \"lwykeym@posterous.com\", \"Male\", \"Pasirmukti\"],\r\n[\"24\", \"Lucie\", \"Kembery\", \"lkemberyn@narod.ru\", \"Female\", \"Uryupinsk\"],\r\n[\"25\", \"Sancho\", \"Mallan\", \"smallano@goodreads.com\", \"Male\", \"\u2018Att\u012bl\"],\r\n[\"26\", \"Rozanna\", \"Leele\", \"rleelep@wp.com\", \"Female\", \"Kobe\"],\r\n[\"27\", \"Hagan\", \"Bryns\", \"hbrynsq@geocities.com\", \"Male\", \"Stockholm\"],\r\n[\"28\", \"Sigvard\", \"Raccio\", \"sraccior@columbia.edu\", \"Male\", \"Sihai\"],\r\n[\"29\", \"Merralee\", \"Denning\", \"mdennings@cloudflare.com\", \"Female\", \"Yanhu\"],\r\n[\"30\", \"Cobbie\", \"Scollard\", \"cscollardt@fda.gov\", \"Male\", \"Damao\"],\r\n[\"31\", \"Neall\", \"Thwaite\", \"nthwaiteu@accuweather.com\", \"Male\", \"Paris 03\"],\r\n[\"32\", \"Byran\", \"Sarll\", \"bsarllv@barnesandnoble.com\", \"Male\", \"Shah Alam\"],\r\n[\"33\", \"Teddie\", \"Mackilpatrick\", \"tmackilpatrickw@ft.com\", \"Male\", \"Dziadkowice\"],\r\n[\"34\", \"Sallyanne\", \"Ellins\", \"sellinsx@newyorker.com\", \"Female\", \"Sovetskiy\"],\r\n[\"35\", \"Wilmette\", \"Airey\", \"waireyy@dion.ne.jp\", \"Female\", \"Kuncen\"],\r\n[\"36\", \"Nicola\", \"Yearne\", \"nyearnez@latimes.com\", \"Male\", \"Al Mijlad\"],\r\n[\"37\", \"Tommi\", \"Marginson\", \"tmarginson10@csmonitor.com\", \"Female\", \"Cibeusi\"],\r\n[\"38\", \"Nealson\", \"Gerrelt\", \"ngerrelt11@free.fr\", \"Male\", \"C\u00e2ndido Mota\"],\r\n[\"39\", \"Dori\", \"Esh\", \"desh12@google.it\", \"Female\", \"Arasji\"],\r\n[\"40\", \"Gus\", \"Quinnette\", \"gquinnette13@shinystat.com\", \"Male\", \"Driefontein\"],\r\n[\"41\", \"Jaime\", \"Radnage\", \"jradnage14@sphinn.com\", \"Male\", \"Lahoysk\"],\r\n[\"42\", \"Alfons\", \"Boodell\", \"aboodell15@eventbrite.com\", \"Male\", \"Tirah\"],\r\n[\"43\", \"Sheila-kathryn\", \"Tutill\", \"stutill16@joomla.org\", \"Female\", \"Bayan Ewenke Minzu\"],\r\n[\"44\", \"Yolanthe\", \"Affuso\", \"yaffuso17@imdb.com\", \"Bigender\", \"San Miguel\"],\r\n[\"45\", \"Renata\", \"Bayston\", \"rbayston18@jimdo.com\", \"Female\", \"Karang Kulon\"],\r\n[\"46\", \"Justinn\", \"Battson\", \"jbattson19@homestead.com\", \"Female\", \"Dalonghua\"],\r\n[\"47\", \"Alys\", \"Ebbing\", \"aebbing1a@tinyurl.com\", \"Female\", \"Stockholm\"],\r\n[\"48\", \"Theodora\", \"Avramovsky\", \"tavramovsky1b@oakley.com\", \"Genderqueer\", \"Il\u2019inskiy Pogost\"],\r\n[\"49\", \"Levin\", \"Jeafferson\", \"ljeafferson1c@fc2.com\", \"Male\", \"Magomeni\"],\r\n[\"50\", \"Arlan\", \"Reddel\", \"areddel1d@tripod.com\", \"Male\", \"Khodzha-Maston\"]\r\n]<\/pre>\n\n<\/div><h2 class=\"tabtitle\">41<\/h2>\n<div class=\"tabcontent\">\n\n<h3 data-start=\"256\" data-end=\"293\"><strong data-start=\"260\" data-end=\"293\">Challenge 41 \u2013 Display a Table<\/strong><\/h3>\n<p data-start=\"295\" data-end=\"468\"><strong data-start=\"295\" data-end=\"305\">Bronze<\/strong><br data-start=\"305\" data-end=\"308\" \/>Write a program that stores the dataset as a list of lists, with the first row as headers. Display the table in a readable format using tab or space separation.<\/p>\n<p data-start=\"470\" data-end=\"616\"><strong data-start=\"470\" data-end=\"480\">Silver<\/strong><br data-start=\"480\" data-end=\"483\" \/>Adjust your program to neatly align the columns. Each column should use a consistent width that is wide enough for the longest entry.<\/p>\n<p data-start=\"618\" data-end=\"778\"><strong data-start=\"618\" data-end=\"626\">Gold<\/strong><br data-start=\"626\" data-end=\"629\" \/>Create a reusable function called <code data-start=\"663\" data-end=\"691\">print_table(headers, rows)<\/code> that accepts any list of headers and rows and prints them in a nicely formatted table.<\/p>\n<hr data-start=\"780\" data-end=\"783\" \/>\n<p data-start=\"785\" data-end=\"841\">\n<\/div><h2 class=\"tabtitle\">42<\/h2>\n<div class=\"tabcontent\">\n<\/p>\n<h3 data-start=\"785\" data-end=\"841\"><strong data-start=\"789\" data-end=\"841\">Challenge 42 \u2013 Improve the Layout and Flexibility<\/strong><\/h3>\n<p data-start=\"843\" data-end=\"1017\"><strong data-start=\"843\" data-end=\"853\">Bronze<\/strong><br data-start=\"853\" data-end=\"856\" \/>Update your <code data-start=\"868\" data-end=\"883\">print_table()<\/code> function so that it calculates the correct column width automatically based on the widest item in each column (including the header).<\/p>\n<p data-start=\"1019\" data-end=\"1181\"><strong data-start=\"1019\" data-end=\"1029\">Silver<\/strong><br data-start=\"1029\" data-end=\"1032\" \/>Add vertical bars (<code data-start=\"1051\" data-end=\"1054\">|<\/code>) to visually separate each column. Your printed table should now resemble an actual table with consistent spacing and borders.<\/p>\n<p data-start=\"1183\" data-end=\"1327\"><strong data-start=\"1183\" data-end=\"1191\">Gold<\/strong><br data-start=\"1191\" data-end=\"1194\" \/>Ensure that your function can handle numbers, strings, and other types gracefully by converting all items to strings before printing.<\/p>\n<hr data-start=\"1329\" data-end=\"1332\" \/>\n<p data-start=\"1334\" data-end=\"1387\">\n<\/div><h2 class=\"tabtitle\">43<\/h2>\n<div class=\"tabcontent\">\n<\/p>\n<h3 data-start=\"1334\" data-end=\"1387\"><strong data-start=\"1338\" data-end=\"1387\">Challenge 43 \u2013 Filtering and Sorting the Table<\/strong><\/h3>\n<p data-start=\"1389\" data-end=\"1551\"><strong data-start=\"1389\" data-end=\"1399\">Bronze<\/strong><br data-start=\"1399\" data-end=\"1402\" \/>Write a function that filters the table by gender (e.g., show only rows where <code data-start=\"1480\" data-end=\"1500\">gender == \"Female\"<\/code>). Allow the user to enter the gender to filter by.<\/p>\n<p data-start=\"1553\" data-end=\"1715\"><strong data-start=\"1553\" data-end=\"1563\">Silver<\/strong><br data-start=\"1563\" data-end=\"1566\" \/>Write a function to sort the table by any column. Let the user choose the column name (like <code data-start=\"1658\" data-end=\"1672\">\"first_name\"<\/code> or <code data-start=\"1676\" data-end=\"1684\">\"city\"<\/code>) and display the sorted table.<\/p>\n<p data-start=\"1717\" data-end=\"1873\"><strong data-start=\"1717\" data-end=\"1725\">Gold<\/strong><br data-start=\"1725\" data-end=\"1728\" \/>Allow the user to choose the sort direction (ascending or descending). Add error handling to make sure the sort column exists and works properly.<\/p>\n<hr data-start=\"1875\" data-end=\"1878\" \/>\n<p data-start=\"1880\" data-end=\"1924\">\n<\/div><h2 class=\"tabtitle\">44<\/h2>\n<div class=\"tabcontent\">\n<\/p>\n<h3 data-start=\"1880\" data-end=\"1924\"><strong data-start=\"1884\" data-end=\"1924\">Challenge 44 \u2013 Search and Menu System<\/strong><\/h3>\n<p data-start=\"1926\" data-end=\"2119\"><strong data-start=\"1926\" data-end=\"1936\">Bronze<\/strong><br data-start=\"1936\" data-end=\"1939\" \/>Allow the user to enter a search term (e.g. <code data-start=\"1983\" data-end=\"1996\">\"Stockholm\"<\/code>), and highlight any matching rows in the table. Highlighting can be done by adding <code data-start=\"2080\" data-end=\"2084\">&gt;&gt;<\/code> at the start of the matching rows.<\/p>\n<p data-start=\"2121\" data-end=\"2176\"><strong data-start=\"2121\" data-end=\"2131\">Silver<\/strong><br data-start=\"2131\" data-end=\"2134\" \/>Create a menu system where the user can:<\/p>\n<ol data-start=\"2177\" data-end=\"2275\">\n<li data-start=\"2177\" data-end=\"2201\">\n<p data-start=\"2180\" data-end=\"2201\">View the full table<\/p>\n<\/li>\n<li data-start=\"2202\" data-end=\"2223\">\n<p data-start=\"2205\" data-end=\"2223\">Filter the table<\/p>\n<\/li>\n<li data-start=\"2224\" data-end=\"2243\">\n<p data-start=\"2227\" data-end=\"2243\">Sort the table<\/p>\n<\/li>\n<li data-start=\"2244\" data-end=\"2265\">\n<p data-start=\"2247\" data-end=\"2265\">Search the table<\/p>\n<\/li>\n<li data-start=\"2266\" data-end=\"2275\">\n<p data-start=\"2269\" data-end=\"2275\">Quit<\/p>\n<\/li>\n<\/ol>\n<p data-start=\"2277\" data-end=\"2373\">The program should loop and return to the menu after each action until the user chooses to quit.<\/p>\n<p data-start=\"2375\" data-end=\"2565\"><strong data-start=\"2375\" data-end=\"2383\">Gold<\/strong><br data-start=\"2383\" data-end=\"2386\" \/>Combine all features: filtering, sorting, and searching. Allow the user to apply multiple operations in sequence and then view the final result using the <code data-start=\"2540\" data-end=\"2555\">print_table()<\/code> function.<\/p>\n<p data-start=\"2375\" data-end=\"2565\">\n<\/div><h2 class=\"tabtitle\">Teacher Resources<\/h2>\n<div class=\"tabcontent\">\n<\/p>\n<h3 data-start=\"2375\" data-end=\"2565\">Teacher Resources<\/h3>\n<p><a href=\"https:\/\/www.mockaroo.com\/\">Mockaroo &#8211; Generator Synthetic Data<\/a><\/p>\n<p>Great for generating sample data to play with tables<\/p>\n<p><a href=\"https:\/\/revise.learnlearn.uk\/static\/static_pages\/csv_to_list.html\">CSV to Python List Convertor<\/a><\/p>\n<p>If students are struggling with the CSV reader then they can load the list data directly in Python to save time and complexity.<\/p>\n<p data-start=\"2375\" data-end=\"2565\"><\/div><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction In programming, a table is a structured way to organize and display data in rows and columns\u2014just like a spreadsheet. Python doesn\u2019t have a built-in table data structure, but you can easily create and work with tables using lists, dictionaries, or third-party libraries like pandas, tabulate, or PrettyTable. A basic table in Python is&hellip;&nbsp;<a href=\"https:\/\/learnlearn.uk\/python\/python-tables\/\" class=\"\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">Python Tables<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"off","neve_meta_content_width":100,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python Tables - Python<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/learnlearn.uk\/python\/python-tables\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Tables - Python\" \/>\n<meta property=\"og:description\" content=\"Introduction In programming, a table is a structured way to organize and display data in rows and columns\u2014just like a spreadsheet. Python doesn\u2019t have a built-in table data structure, but you can easily create and work with tables using lists, dictionaries, or third-party libraries like pandas, tabulate, or PrettyTable. A basic table in Python is&hellip;&nbsp;Read More &raquo;Python Tables\" \/>\n<meta property=\"og:url\" content=\"https:\/\/learnlearn.uk\/python\/python-tables\/\" \/>\n<meta property=\"og:site_name\" content=\"Python\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-05T09:45:42+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/learnlearn.uk\/python\/python-tables\/\",\"url\":\"https:\/\/learnlearn.uk\/python\/python-tables\/\",\"name\":\"Python Tables - Python\",\"isPartOf\":{\"@id\":\"https:\/\/learnlearn.uk\/python\/#website\"},\"datePublished\":\"2025-06-04T07:11:25+00:00\",\"dateModified\":\"2025-06-05T09:45:42+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/learnlearn.uk\/python\/python-tables\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/learnlearn.uk\/python\/python-tables\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/learnlearn.uk\/python\/python-tables\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Python Unit Home\",\"item\":\"https:\/\/learnlearn.uk\/python\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python Tables\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/learnlearn.uk\/python\/#website\",\"url\":\"https:\/\/learnlearn.uk\/python\/\",\"name\":\"Python\",\"description\":\"Programming\",\"publisher\":{\"@id\":\"https:\/\/learnlearn.uk\/python\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/learnlearn.uk\/python\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/learnlearn.uk\/python\/#organization\",\"name\":\"Python\",\"url\":\"https:\/\/learnlearn.uk\/python\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/learnlearn.uk\/python\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2019\/03\/LearnLearnLogowhite.png\",\"contentUrl\":\"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2019\/03\/LearnLearnLogowhite.png\",\"width\":710,\"height\":98,\"caption\":\"Python\"},\"image\":{\"@id\":\"https:\/\/learnlearn.uk\/python\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Tables - Python","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/learnlearn.uk\/python\/python-tables\/","og_locale":"en_GB","og_type":"article","og_title":"Python Tables - Python","og_description":"Introduction In programming, a table is a structured way to organize and display data in rows and columns\u2014just like a spreadsheet. Python doesn\u2019t have a built-in table data structure, but you can easily create and work with tables using lists, dictionaries, or third-party libraries like pandas, tabulate, or PrettyTable. A basic table in Python is&hellip;&nbsp;Read More &raquo;Python Tables","og_url":"https:\/\/learnlearn.uk\/python\/python-tables\/","og_site_name":"Python","article_modified_time":"2025-06-05T09:45:42+00:00","twitter_card":"summary_large_image","twitter_misc":{"Estimated reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/learnlearn.uk\/python\/python-tables\/","url":"https:\/\/learnlearn.uk\/python\/python-tables\/","name":"Python Tables - Python","isPartOf":{"@id":"https:\/\/learnlearn.uk\/python\/#website"},"datePublished":"2025-06-04T07:11:25+00:00","dateModified":"2025-06-05T09:45:42+00:00","breadcrumb":{"@id":"https:\/\/learnlearn.uk\/python\/python-tables\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/learnlearn.uk\/python\/python-tables\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/learnlearn.uk\/python\/python-tables\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Python Unit Home","item":"https:\/\/learnlearn.uk\/python\/"},{"@type":"ListItem","position":2,"name":"Python Tables"}]},{"@type":"WebSite","@id":"https:\/\/learnlearn.uk\/python\/#website","url":"https:\/\/learnlearn.uk\/python\/","name":"Python","description":"Programming","publisher":{"@id":"https:\/\/learnlearn.uk\/python\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/learnlearn.uk\/python\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-GB"},{"@type":"Organization","@id":"https:\/\/learnlearn.uk\/python\/#organization","name":"Python","url":"https:\/\/learnlearn.uk\/python\/","logo":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/learnlearn.uk\/python\/#\/schema\/logo\/image\/","url":"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2019\/03\/LearnLearnLogowhite.png","contentUrl":"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2019\/03\/LearnLearnLogowhite.png","width":710,"height":98,"caption":"Python"},"image":{"@id":"https:\/\/learnlearn.uk\/python\/#\/schema\/logo\/image\/"}}]}},"rttpg_featured_image_url":null,"rttpg_author":{"display_name":"learnlearnadmin","author_link":"https:\/\/learnlearn.uk\/python\/author\/learnlearnadmin\/"},"rttpg_comment":0,"rttpg_category":null,"rttpg_excerpt":"Introduction In programming, a table is a structured way to organize and display data in rows and columns\u2014just like a spreadsheet. Python doesn\u2019t have a built-in table data structure, but you can easily create and work with tables using lists, dictionaries, or third-party libraries like pandas, tabulate, or PrettyTable. A basic table in Python is&hellip;&nbsp;Read&hellip;","_links":{"self":[{"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/pages\/1512"}],"collection":[{"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/comments?post=1512"}],"version-history":[{"count":9,"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/pages\/1512\/revisions"}],"predecessor-version":[{"id":1526,"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/pages\/1512\/revisions\/1526"}],"wp:attachment":[{"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/media?parent=1512"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}