Skip to main content
deleted 263 characters in body
Source Link
lynn
  • 69.7k
  • 11
  • 137
  • 285

insteadInstead of range(x), you can use the ** operator on a list of anything, if you don't actually need to use the value of i:

for i in[1]*8:pass 

as opposed to

for i in range(8):pass 

note you save yet another character by omitting the space before [

ifIf you need to do this more than twice, you could assign any iterable to a variable, and multiply that variable by the range you want:

r=[1]r=1, for i in r*8:pass for i in r*1000:pass 

as opposed to:

r=range for i in r(8):pass for i in r(1000):pass 

editNote: saving 1 more characterthis is often longer than exec"pass;"*8, you can use tuple notation instead of a character or list:

r=1, for i in r*8:pass 

but that won't work if youso this trick should only need to use it once:be used when that isn't an option.

for i in 1,*8:pass # this is invalid syntax 

instead of range(x), you can use the * operator on a list of anything, if you don't actually need to use the value of i:

for i in[1]*8: 

as opposed to

for i in range(8): 

note you save yet another character by omitting the space before [

if you need to do this more than twice, you could assign any iterable to a variable, and multiply that variable by the range you want:

r=[1] for i in r*8:pass for i in r*1000:pass 

as opposed to:

r=range for i in r(8):pass for i in r(1000):pass 

edit: saving 1 more character, you can use tuple notation instead of a character or list:

r=1, for i in r*8:pass 

but that won't work if you only need to use it once:

for i in 1,*8:pass # this is invalid syntax 

Instead of range(x), you can use the * operator on a list of anything, if you don't actually need to use the value of i:

for i in[1]*8:pass 

as opposed to

for i in range(8):pass 

If you need to do this more than twice, you could assign any iterable to a variable, and multiply that variable by the range you want:

r=1, for i in r*8:pass for i in r*1000:pass 

Note: this is often longer than exec"pass;"*8, so this trick should only be used when that isn't an option.

Mod Removes Wiki by Doorknob
returned the removed line
Source Link
proud haskeller
  • 6.1k
  • 1
  • 24
  • 37

instead of range(x), you can use the * operator on a list of anything, if you don't actually need to use the value of i:

for i in[1]*8: 

as opposed to

for i in range(8): 

note you save yet another character by omitting the space before [

if you need to do this more than twice, you could assign any iterable to a variable, and multiply that variable by the range you want:

r=[1] for i in r*8:pass for i in r*1000:pass 

as opposed to:

r=range for i in r(8):pass for i in r(1000):pass 

edit: saving 1 more character, you can use tuple notation instead of a character or list:

r=1, for i in r*8:pass 

but that won't work if you only need to use it once:

for i in 1,*8:pass # this is invalid syntax 

instead of range(x), you can use the * operator on a list of anything, if you don't actually need to use the value of i:

for i in[1]*8: 

as opposed to

for i in range(8): 

if you need to do this more than twice, you could assign any iterable to a variable, and multiply that variable by the range you want:

r=[1] for i in r*8:pass for i in r*1000:pass 

as opposed to:

r=range for i in r(8):pass for i in r(1000):pass 

edit: saving 1 more character, you can use tuple notation instead of a character or list:

r=1, for i in r*8:pass 

but that won't work if you only need to use it once:

for i in 1,*8:pass # this is invalid syntax 

instead of range(x), you can use the * operator on a list of anything, if you don't actually need to use the value of i:

for i in[1]*8: 

as opposed to

for i in range(8): 

note you save yet another character by omitting the space before [

if you need to do this more than twice, you could assign any iterable to a variable, and multiply that variable by the range you want:

r=[1] for i in r*8:pass for i in r*1000:pass 

as opposed to:

r=range for i in r(8):pass for i in r(1000):pass 

edit: saving 1 more character, you can use tuple notation instead of a character or list:

r=1, for i in r*8:pass 

but that won't work if you only need to use it once:

for i in 1,*8:pass # this is invalid syntax 
the space wasn't there already
Source Link
proud haskeller
  • 6.1k
  • 1
  • 24
  • 37

instead of range(x), you can use the * operator on a list of anything, if you don't actually need to use the value of i:

for i in[1]*8: 

as opposed to

for i in range(8): 

note you save yet another character by omitting the space before [

if you need to do this more than twice, you could assign any iterable to a variable, and multiply that variable by the range you want:

r=[1] for i in r*8:pass for i in r*1000:pass 

as opposed to:

r=range for i in r(8):pass for i in r(1000):pass 

edit: saving 1 more character, you can use tuple notation instead of a character or list:

r=1, for i in r*8:pass 

but that won't work if you only need to use it once:

for i in 1,*8:pass # this is invalid syntax 

instead of range(x), you can use the * operator on a list of anything, if you don't actually need to use the value of i:

for i in[1]*8: 

as opposed to

for i in range(8): 

note you save yet another character by omitting the space before [

if you need to do this more than twice, you could assign any iterable to a variable, and multiply that variable by the range you want:

r=[1] for i in r*8:pass for i in r*1000:pass 

as opposed to:

r=range for i in r(8):pass for i in r(1000):pass 

edit: saving 1 more character, you can use tuple notation instead of a character or list:

r=1, for i in r*8:pass 

but that won't work if you only need to use it once:

for i in 1,*8:pass # this is invalid syntax 

instead of range(x), you can use the * operator on a list of anything, if you don't actually need to use the value of i:

for i in[1]*8: 

as opposed to

for i in range(8): 

if you need to do this more than twice, you could assign any iterable to a variable, and multiply that variable by the range you want:

r=[1] for i in r*8:pass for i in r*1000:pass 

as opposed to:

r=range for i in r(8):pass for i in r(1000):pass 

edit: saving 1 more character, you can use tuple notation instead of a character or list:

r=1, for i in r*8:pass 

but that won't work if you only need to use it once:

for i in 1,*8:pass # this is invalid syntax 
Source Link
Blazer
  • 2.3k
  • 1
  • 19
  • 14
Loading