importing module inside of a list comprehension in python
Question:
The below program will show loading
in console. Can we make it one line?
For that to happen we need to import time
module inside of list comprehension
.
How can we import module inside of list comprehension
?
import time
[print(f"rLoading... " + (('|', '/', '-', '\')[i % 4]) + "t", end="") or time.sleep(0.10) for i in range(100) ]
Answers:
You could do it like this but this is not a recommendation:
[print(time:=__import__('time'), f"
The below program will show loading
in console. Can we make it one line?
For that to happen we need to import time
module inside of list comprehension
.
How can we import module inside of list comprehension
?
import time
[print(f"rLoading... " + (('|', '/', '-', '\')[i % 4]) + "t", end="") or time.sleep(0.10) for i in range(100) ]
You could do it like this but this is not a recommendation:
[print(time:=__import__('time'), f"