Skip to content

Instantly share code, notes, and snippets.

@TheBeachMaster
Last active August 29, 2015 14:11
Show Gist options
  • Save TheBeachMaster/54087e7de9ef1917e7f3 to your computer and use it in GitHub Desktop.
Save TheBeachMaster/54087e7de9ef1917e7f3 to your computer and use it in GitHub Desktop.
Introductory Python on simple list manipulations
# coding=utf-8
# coding=utf-8
__author__ = 'Kennedy Otieno'
# let's begin with lists
agelist = [12, 22, 33, 14, 92, 65, 74, 13, 98, 44, 22, 78]
firstsum = agelist[0] + agelist[4] # we'd like to manipulate the data stored in agelist we should get 104
print(firstsum)
secondsum = agelist[-4] - agelist[-6] # we should get 98-74=24
print(secondsum)
# let's do some slicing with this list
slice1 = agelist[3:5] # should print 14 & 92
print(slice1)
slice2 = agelist[4:] # should print 92...78
print(slice2)
slice3 = agelist[-4:] # should print 13...12
print(slice3)
slice4 = agelist[:5] # should print 12...92
print(slice4)
# let's do some skipping
skip1 = agelist[::2] # should print 12,33,92,74,98,22 unless we made a mistake ☺
print(skip1)
skip2 = agelist[-1::-3] # should do the above but backwards hence the values skipped above
print(skip2)
skip3 = agelist[2:7:2] # should print third number to sixth number while skipping a digit . hope so!
print(skip3)
skip4 = agelist[-1:-8:-3] # should print from last digit to last digit-from right- while skipping 2 digits
print(skip4)
agelist1 = [14, 73, 15, 96, 52, 41, 83, 44, 61]
concat1 = agelist1 + agelist # guess what this does?
print(concat1)
# let's sort concat 1
# concat2 = concat1.sort() # sorts itself !
# print(concat2)
word = raw_input("Enter your line: ")
newword = sorted(word)
print(newword)
# k="e" in word
# print(k)
k= raw_input("Enter the word or letter to search: ")
rel= k in word
print(rel)
print"Your line contains the following number of characters ",len(word)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment