Python Forum
Indexing + ''.join Help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Indexing + ''.join Help
#1
I'm not a programmer; I'm taking my first course in Python and I have absolutely no experience, so please excuse this if it's mindbogglingly simple and I'm just a dummy.

I have to do an assignment and can't get past the second question:
def make_str_from_row(board, row_index):
    """ (list of list of str, int) -> str

    Return the characters from the row of the board with index row_index
    as a single string.

    >>> make_str_from_row([['A', 'N', 'T', 'T'], ['X', 'S', 'O', 'B']], 0)
    'ANTT'
    """
I have figured out in my practice shell what it is that I need to do (i.e. isolate the indexed board, then use ''.join() to return the characters as a single string). However, I can't seem to get the code correct in my .py file. Could someone please explain to me what I have to do here? The assignment is due in 36 hours and I'm freaking out.
Reply
#2
Show what you have done so far and what problems you are having that people can help with. If you get an error show the full traceback.
Reply
#3
Based on the timing of your post, and 36 hours, it sounds like you missed the deadline.  For future reference, include what you've already done, the output you're getting, and the output you want to be getting, along with any error messages.  Otherwise, we're not going to do your homework for you :p

This particular example is fairly straightforward.  Here's one possible solution:
>>> make_str_from_row = lambda x,y: ''.join(x[y])
>>> make_str_from_row([['A', 'N', 'T', 'T'], ['X', 'S', 'O', 'B']], 0)
'ANTT'
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020