Python Map

  • Comments posted to this topic are about the item Python Map

  • Nice question, thanks Steve

    ____________________________________________
    Space, the final frontier? not any more...
    All limits henceforth are self-imposed.
    “libera tute vulgaris ex”

  • the second line of code inside your function should be indented

    def calcsq(n):
    return n*n
  • A little bit tricky for me, the code as is (ignoring the missing indentation) would fail since calcsq is defined as calcsq then called as calcSq, the differing case would result in an exception. Fortunately returning an exception wasn't one of the available choices or I wouldn't have dug any further. Additionally print(result) doesn't print the values from the map object it prints "<map object at 0x000001..." you need to convert it to a set or list first to see the values in a print command (Python 3.7), good thing all the answers were lists or I wouldn't have dug deeper here either. Good question, I'm new to python so these questions give me direction of what functions to go learn about and play with. I find these very valuable, thanks.

    -

  • Will not execute with indent error.

  • Jason, Hahahaha, love it! Keep up the good work.

    • This reply was modified 4 years, 3 months ago by  MESONMARCUS.
  • Hahahaha, love it! Keep up the good work.

  • I've added the indentation and corrected the case of calcsq.

     

    Thanks,

    Kathi

  • The print statement also needs to be changed to print(list(result))

  • Picky, picky, picky.  If you expect perfection in the questions, sorry, but that may not happen.  Personally, I am lucky to even be able to spell Python as I don't currently use it.  So I thought about the question logically, figured that calcsq computed the square of a value and that the map some how iterated over the list.  Made the correct choice.

    Hoping this means when I start work on learning Python it shouldn't be too difficult since I seem to be able to grasp some of the concepts.

     

  • OK, corrected that, too.

  • Hmmm ... oddly, print (result) in Python v2.7.13 displays the result correctly. No need to add list().

  • Well that's strange.  I'm just starting to learn Python and have v3.8.1 installed.  If I use print(result) I get <map object at 0x00000000027C6E80>.  If I use print(list(result)) I get [4, 9, 16, 25].

  • Lynn Pettis, the difference in genetic structure between humans and chimps is around 4%. The pickyness of evolution is what gave rise to humans. One error in one line of code could result in AI eradicating biological life. We need to teach our developing programmers that pickyness is everything. 😉

  • Now I wait for someone to be picky and correct my spelling of pickiness.

Viewing 15 posts - 1 through 15 (of 16 total)

You must be logged in to reply to this topic. Login to reply