In [1]:
days = ['yesterday','today','tomorrow','dayafter']
In [2]:
# task1
for value in days:
print value,len(value)
In [4]:
# task2
for value in days:
print value,days.index(value)
In [5]:
for value in days:
print value,days.index(value),value[days.index(value)]
In [7]:
for value in days:
print value,days.index(value),value[0:days.index(value) + 1]
In [8]:
# my_string
my_string="python"
print my_string[0:3] # pyt
print my_string[:3] # pyt
print my_string[3:] # hon
print my_string[:3] + my_string[3:]
In [10]:
for value in days:
print value[:days.index(value) + 1].upper() + value[days.index(value) + 1:]
In [4]:
# task2
my_fruits = ['apple','apple','banana','banana','banana','cherry','apple']
# my_fruits = ['apple','banana','cherry']
# my_dupli = ['apple','banana']
my_dupli=[]
for value in my_fruits:
print "looking into value - {}".format(value)
if my_fruits.count(value) > 1:
if not value in my_dupli:
my_dupli.append(value)
my_fruits.remove(value)
print my_fruits
print my_dupli
In [5]:
# deep copy
my_fruits =['apple','banana','cherry']
my_new = my_fruits[:]
print my_fruits,my_new
print my_fruits is my_new
In [6]:
import copy
my_fruits =['apple','banana','cherry']
my_new = copy.deepcopy(my_fruits)
print my_fruits,my_new
print my_fruits is my_new
In [7]:
# soft copy
my_fruits =['apple','banana','cherry']
my_new = my_fruits
print my_fruits,my_new
print my_fruits is my_new
In [ ]: