2

My code is like this:

def f1(x):
    return x**x

L = [1,2,3,4,5,6,7,8,9,10,11]
map(f1, L)

and the result shows:

[1, 4, 27, 256, 3125, 46656, 823543, 16777216, 387420489, 10000000000L, 285311670611L]

I tried this both on my windows and Ubuntu system, it's the same result, is there something wrong with my code or my python or something else?

Zen
  • 4,381
  • 5
  • 29
  • 56
  • Unrelated, but you could do this without defining ```f1()``` separately by doing ```map(lambda x: x**x, L)``` – wnnmaw Apr 03 '14 at 10:05

2 Answers2

1

If you are referring to the L appended to the numbers, it signifies that they are long integers and you shouldn't worry about it. They don't affect calculations done on them.

elbear
  • 769
  • 8
  • 16
  • but if I print them out, will they still show that L on user's screen? – Zen Apr 03 '14 at 10:33
  • Nope. Try this `print '%d' % L[9]`, where `L` is your list of integers. – elbear Apr 03 '14 at 10:39
  • @Zen: No. Just print `L[10]` and have a look at the result. You don't use something like `print(L)` in your code, don't you? – Matthias Apr 03 '14 at 10:40
  • I tried to type something like a=[21312321235345345345345], and print a later, it shows L in my python command line. – Zen Apr 03 '14 at 10:46
  • Because you are printing the list. If you print the individual integer, `L` doesn't show up. – elbear Apr 03 '14 at 10:48
0

int and long were "unified" a few versions back. Before that it was possible to overflow an int through math ops.

3.x has further advanced this by eliminating int altogether and only having long.

sys.maxint contains the maximum value a Python int can hold.

Furquan Khan
  • 1,586
  • 1
  • 15
  • 30