Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9097791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:12:13+00:00 2026-06-17T00:12:13+00:00

Input [[‘1′,’2′,’3’],[‘a’,’b’,’c’],[‘6′,’7′,’8’],[‘e’,’f’,’g’]] Output should be: 1, 2, 3 a, b, c 6, 7, 8

  • 0

Input

[['1','2','3'],['a','b','c'],['6','7','8'],['e','f','g']]

Output should be:

1, 2, 3
a, b, c
6, 7, 8
e, f, g

Code:

def print_row(los):
    print ', '.join(los)


def print_table(los):
    lose = []
    if los  == []:
        return
    else:
        return print_row(los[0]) + print_table(los[1:]) 

Currently:

print_table([['1','2','3'],['a','b','c'],['6','7','8'],['e','f','g']])

Gives:

1, 2, 3
a, b, c
6, 7, 8
e, f, g

TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType'

How do I fix this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T00:12:15+00:00Added an answer on June 17, 2026 at 12:12 am

    Your function returns None (an empty return statement). Return an empty string instead:

    if los == []:
        return ''
    

    You also have a lose definition there that is never used, and you can test for the empty list with not los. Last but not least, since return exits the function early, the else: statement is optional.

    Next, print_row() returns None as well, since you don’t return anything from it. Simply discard it’s return value:

    def print_table(los):
        if not los:
            return ''
        print_row(los[0])
        return print_table(los[1:]) 
    

    Note that you never use the return value of print_table anyway, so you may as well not return anything; simply test if there is anything to print:

    def print_table(los):
        if los:
            print_row(los[0])
            print_table(los[1:]) 
    

    Now you can just inline the print_row function (which is just a one-liner):

    def print_table(los):
        if los:
            print ', '.join(los[0])
            print_table(los[1:]) 
    

    This is still recursive; Python isn’t that strong at recursion, but it can do looping very well:

    def print_table(los):
        for sublist in los:
            print ', '.join(sublist)
    

    which can be reduced to a join on newlines too:

    def print_table(los):
        print '\n'.join(', '.join(sublist) for sublist in los)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Input file .. set name old name; # comment should be updated .. Output
Input : {5, 13, 6, 5, 13, 7, 8, 6, 5} Output : {5,
Input: SHC 111U,SHB 22x,, SHA 5555G Needed output: SHB 22X, SHC 111U, SHA 5555G
Input: I have a LaTeX file, with plain text & math formulas. Desired output:
Input col1, col2, col3, coln Output @col1, @col2, @col3, @coln
Input: Hi. I am John. My name is John. Who are you ? Output:
Input: set firstList to {'red ball','blue','yellow'} set secondList to {'grasshopper','yellowjacket','blueberry','redball'} Output: {'yellowjacket','blueberry','redball'} What's the
input: ['abc', 'cab', 'cafe', 'face', 'goo'] output: [['abc', 'cab'], ['cafe', 'face'], ['goo']] The problem
Input: An array of n positive and negative numbers and a number k. Output:
Input: df -k Output: Filesystem kbytes used avail capacity Mounted on /dev/dsk/c0t0d0s0 10332220 443748

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.