In [1]:
print hex(1024)
Problem 2: Round 5.23222 to two decimal places
In [2]:
print round(5.23222,2)
In [3]:
s = 'hello how are you Mary, are you feeling okay?'
In [12]:
retVal = 1
for word in s.split():
print word
for item in word:
# print item
if not item.islower():
# print item
print 'The string has Uppercase characters'
retVal = 0
break
print retVal
In [13]:
s.islower()
Out[13]:
Problem 4: How many times does the letter 'w' show up in the string below?
In [14]:
s = 'twywywtwywbwhsjhwuwshshwuwwwjdjdid'
s.count('w')
Out[14]:
Problem 5: Find the elements in set1 that are not in set2:
In [15]:
set1 = {2,3,1,5,6,8}
set2 = {3,1,7,5,6,8}
set1.difference(set2)
Out[15]:
Problem 6: Find all elements that are in either set:
In [16]:
set1.intersection(set2)
Out[16]:
In [17]:
{ val:val**3 for val in xrange(0,5)}
Out[17]:
In [25]:
l = [1,2,3,4]
l[::-1]
Out[25]:
Problem 9: Sort the list below
In [29]:
l = [3,4,2,5,1]
sorted(l)
Out[29]: