The are not the same exactly, but the difference is minimal. When in doubt, use the dis module to find out:
>>> import dis
>>> def f():
... for a in sorted(arr):
... doSomething()
...
>>> def g():
... sArr = sorted(arr)
... for a in sArr:
... doSomething()
...
>>> dis.dis(f)
2 0 SETUP_LOOP 27 (to 30)
3 LOAD_GLOBAL 0 (sorted)
6 LOAD_GLOBAL 1 (arr)
9 CALL_FUNCTION 1
12 GET_ITER
>> 13 FOR_ITER 13 (to 29)
16 STORE_FAST 0 (a)
3 19 LOAD_GLOBAL 2 (doSomething)
22 CALL_FUNCTION 0
25 POP_TOP
26 JUMP_ABSOLUTE 13
>> 29 POP_BLOCK
>> 30 LOAD_CONST 0 (None)
33 RETURN_VALUE
>>> dis.dis(g)
2 0 LOAD_GLOBAL 0 (sorted)
3 LOAD_GLOBAL 1 (arr)
6 CALL_FUNCTION 1
9 STORE_FAST 0 (sArr)
3 12 SETUP_LOOP 21 (to 36)
15 LOAD_FAST 0 (sArr)
18 GET_ITER
>> 19 FOR_ITER 13 (to 35)
22 STORE_FAST 1 (a)
4 25 LOAD_GLOBAL 2 (doSomething)
28 CALL_FUNCTION 0
31 POP_TOP
32 JUMP_ABSOLUTE 19
>> 35 POP_BLOCK
>> 36 LOAD_CONST 0 (None)
39 RETURN_VALUE
As you can see, the g() function adds a STORE_FAST and LOAD_FAST operation. You also use a little more memory, as the sorted results are kept around until the sArr variable is cleaned up, while in f() the sorted results can be cleaned up immediately following the conclusion of the loop.
The CALL_FUNCTION executes the sorted() function; it is only executed once.