In [10]:
old_string = "hello"
new_string = ""
for i in xrange(len(old_string)-1, -1, -1):
new_string += old_string[i]
assert old_string[0] == new_string[-1]
assert old_string[-1] == new_string[0]
In [11]:
"hello"[::-1]
Out[11]:
In [ ]:
class Node():
left nul
In [1]:
def extendList(val, list=[]):
list.append(val)
return list
list1 = extendList(10)
list2 = extendList(123,[])
list3 = extendList('a')
print "list1 = %s" % list1
print "list2 = %s" % list2
print "list3 = %s" % list3
In [5]:
def eL(val, new_list=[]):
new_list.append(val)
return new_list
print eL(10)
print eL(123,[])
print eL(10)
In [11]:
def func():
new_value = 1
return new_value
func(10)
In [12]:
def multipliers():
return [lambda x : i * x for i in range(4)]
print [m(2) for m in multipliers()]
In [23]:
[l(1) for l in [lambda x : i * x for i in xrange(4)]]
Out[23]:
In [25]:
[2 * x for x in [i for i in xrange(4)]]
Out[25]: