omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Head First Python problem

    Pythonista
    2
    4
    2786
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • HatePastaCode74
      HatePastaCode74 last edited by

      I just started learning Python with Pythonista and the book 'Head First Python'

      There is an exercise which I do not understand. I create a list variable: eg
      movies = [ 'and', 'bin', 'can','den']
      and then the code snippet:
      for each_item in movies: print(each_item)
      and
      bin
      can
      den

      Which as expected prints each string on a new line. When I put this code into this function:

      def print_list(My_list):
      for an_item in My_list:
      if isinstance(My_list,list):
      print_list(an_item)
      else:
      print(an_item)
      print_list(movies)

      the list entries print out each character of each string on a new line. What is going on here?
      a
      n
      d
      b
      i
      n
      .
      .
      .

      1 Reply Last reply Reply Quote 0
      • Gcarver166
        Gcarver166 last edited by

        I think you want if isinstance(an_item, list):

        1 Reply Last reply Reply Quote 0
        • Gcarver166
          Gcarver166 last edited by

          I think You want if isinstance(an_item, list):

          1 Reply Last reply Reply Quote 0
          • HatePastaCode74
            HatePastaCode74 last edited by

            Thanks,
            that works.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Powered by NodeBB Forums | Contributors