- 145.6k
- 22
- 190
- 479
Like @Mast mentioned already mentioned you should use proper variable named in your program. A good variable name makes the program so much easier to read, specially if you're reading it after couple of months.
There are only two hard things in Computer Science: cache invalidation and naming things. --— Phil Karlton
e = int(len(nl))
e = int(len(nl))
The call to
int()
is redundant, length is always an integer.Given integer operands you can get floored division in both Python 2 and 3 using //
//
operator. This prevents theint()
conversions as we are not dealing with floats here.Return your result instead of printing it. That way you can import this function in other modules as well, making it re-usable.
New version of your program:
def median(seq):
new_list = sorted(seq)
length = len(seq)
if length % 2 != 0:
index = length // 2
median = new_list[index]
else:
index_right = length // 2
index_left = index_right - 1
median = (new_list[index_left] + new_list[index_right]) / 2.0
return median
Like @Mast mentioned already mentioned you should use proper variable named in your program. A good variable name makes the program so much easier to read, specially if you're reading it after couple of months.
There are only two hard things in Computer Science: cache invalidation and naming things. -- Phil Karlton
e = int(len(nl))
The call to
int()
is redundant, length is always an integer.Given integer operands you can get floored division in both Python 2 and 3 using // operator. This prevents the
int()
conversions as we are not dealing with floats here.Return your result instead of printing it. That way you can import this function in other modules as well, making it re-usable.
New version of your program:
def median(seq):
new_list = sorted(seq)
length = len(seq)
if length % 2 != 0:
index = length // 2
median = new_list[index]
else:
index_right = length // 2
index_left = index_right - 1
median = (new_list[index_left] + new_list[index_right]) / 2.0
return median
Like @Mast mentioned already mentioned you should use proper variable named in your program. A good variable name makes the program so much easier to read, specially if you're reading it after couple of months.
There are only two hard things in Computer Science: cache invalidation and naming things. — Phil Karlton
-
e = int(len(nl))
The call to
int()
is redundant, length is always an integer. Given integer operands you can get floored division in both Python 2 and 3 using
//
operator. This prevents theint()
conversions as we are not dealing with floats here.Return your result instead of printing it. That way you can import this function in other modules as well, making it re-usable.
New version of your program:
def median(seq):
new_list = sorted(seq)
length = len(seq)
if length % 2 != 0:
index = length // 2
median = new_list[index]
else:
index_right = length // 2
index_left = index_right - 1
median = (new_list[index_left] + new_list[index_right]) / 2.0
return median
- Like @Mast mentioned already mentioned you should use proper variable named in your program. A good variable name makes the program so much easier to read, specially if you're reading it after couple of months.
Like @Mast mentioned already mentioned you should use proper variable named in your program. A good variable name makes the program so much easier to read, specially if you're reading it after couple of months.
There are only two hard things in Computer Science: cache invalidation and naming things. -- Phil Karlton
e = int(len(nl))
The call to
int()
is redundant, length is always an integer.Given integer operands you can get floored division in both Python 2 and 3 using // operator. This prevents the
int()
conversions as we are not dealing with floats here.Return your result instead of printing it. That way you can import this function in other modules as well, making it re-usable.
There are only two hard things in Computer Science: cache invalidation and naming things. -- Phil Karlton
e = int(len(nl))
The call to int()
is redundant, length is always an integer.
Given integer operands you can get floored division in both Python 2 and 3 using // operator. This prevents the
int()
conversions as we are not dealing with floats here.Return your result instead of printing it. That was you can import this function in other modules as well, making it re-usable.
New version of your program:
def median(seq):
new_list = sorted(seq)
length = len(seq)
if length % 2 != 0:
index = length // 2
median = new_list[index]
else:
index_right = length // 2
index_left = index_right - 1
median = (new_list[index_left] + new_list[index_right]) / 2.0
return median
- Like @Mast mentioned already mentioned you should use proper variable named in your program. A good variable name makes the program so much easier to read, specially if you're reading it after couple of months.
There are only two hard things in Computer Science: cache invalidation and naming things. -- Phil Karlton
e = int(len(nl))
The call to int()
is redundant, length is always an integer.
Given integer operands you can get floored division in both Python 2 and 3 using // operator. This prevents the
int()
conversions as we are not dealing with floats here.Return your result instead of printing it. That was you can import this function in other modules as well, making it re-usable.
New version of your program:
def median(seq):
new_list = sorted(seq)
length = len(seq)
if length % 2 != 0:
index = length // 2
median = new_list[index]
else:
index_right = length // 2
index_left = index_right - 1
median = (new_list[index_left] + new_list[index_right]) / 2.0
return median
Like @Mast mentioned already mentioned you should use proper variable named in your program. A good variable name makes the program so much easier to read, specially if you're reading it after couple of months.
There are only two hard things in Computer Science: cache invalidation and naming things. -- Phil Karlton
e = int(len(nl))
The call to
int()
is redundant, length is always an integer.Given integer operands you can get floored division in both Python 2 and 3 using // operator. This prevents the
int()
conversions as we are not dealing with floats here.Return your result instead of printing it. That way you can import this function in other modules as well, making it re-usable.
New version of your program:
def median(seq):
new_list = sorted(seq)
length = len(seq)
if length % 2 != 0:
index = length // 2
median = new_list[index]
else:
index_right = length // 2
index_left = index_right - 1
median = (new_list[index_left] + new_list[index_right]) / 2.0
return median
- Like @Mast mentioned already mentioned you should use proper variable named in your program. A good variable name makes the program so much easier to read, specially if you're reading it after couple of months.
There are only two hard things in Computer Science: cache invalidation and naming things. -- Phil Karlton
e = int(len(nl))
The call to int()
is redundant, length is always an integer.
Given integer operands you can get floored division in both Python 2 and 3 using // operator. This prevents the
int()
conversions as we are not dealing with floats here.Return your result instead of printing it. That was you can import this function in other modules as well, making it re-usable.
New version of your program:
def median(seq):
new_list = sorted(seq)
length = len(seq)
if length % 2 != 0:
index = length // 2
median = new_list[index]
else:
index_right = length // 2
index_left = index_right - 1
median = (new_list[index_left] + new_list[index_right]) / 2.0
return median