Techtalks: Traveltech

Python Code Error

Hi

I am using built in functions and libraries for this python code and I am trying to execute this code, but it is showing NameError.

 

import time
   
# slower (Without map())
start = time.clock() 
s = 'geeks'
U = []
for c in s:
    U.append(c.upper())
print (U)
elapsed = time.clock()
e1 = elapsed - start
print ("Time spent in function is: ", e1)
   
# Faster (Uses builtin function map())
s = 'geeks'
start = time.clock() 
U = map(str.upper, s) 
print (U)
elapsed = time.clock()
e2 = elapsed - start
print ("Time spent in builtin function is: ", e2)

 

Thanks.

image placeholder
Harish Mehra

asked  Sep 7, 2022

2800views
5answers
0votes
image placeholder
James Harry, Digital Trainer at igmGuru

answered  Oct 17, 2022

0
image placeholder
Abdul moeez

answered  May 13, 2024

0
image placeholder
umar khan

answered  May 16, 2024

0
image placeholder
zarion bart

answered  May 18, 2024

0
image placeholder
cerehal253 cerehal253

answered  May 19, 2024

0