Python Map

  • Steve Jones - SSC Editor

    SSC Guru

    Points: 717276

    Comments posted to this topic are about the item Python Map

  • Stewart "Arturius" Campbell

    SSC Guru

    Points: 71566

    Nice question, thanks Steve

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

  • Marek Grzymala

    SSCommitted

    Points: 1928

    the second line of code inside your function should be indented

    def calcsq(n):
    return n*n
  • Jason-

    SSCrazy

    Points: 2536

    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.

    -

  • MESONMARCUS

    Grasshopper

    Points: 20

    Will not execute with indent error.

  • MESONMARCUS

    Grasshopper

    Points: 20

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

    • This reply was modified 4 days, 23 hours ago by  MESONMARCUS.
  • MESONMARCUS

    Grasshopper

    Points: 20

    Hahahaha, love it! Keep up the good work.

  • Kathi Kellenberger

    SSC Veteran

    Points: 243

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

     

    Thanks,

    Kathi

  • johnfowler

    Ten Centuries

    Points: 1215

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

  • Lynn Pettis

    SSC Guru

    Points: 442205

    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.

     

  • Kathi Kellenberger

    SSC Veteran

    Points: 243

    OK, corrected that, too.

  • George Vobr

    SSCrazy Eights

    Points: 9055

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

  • johnfowler

    Ten Centuries

    Points: 1215

    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].

  • MESONMARCUS

    Grasshopper

    Points: 20

    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. 😉

  • MESONMARCUS

    Grasshopper

    Points: 20

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

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

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