def tup_removemid(lista, numberstart, numberend):
'''
Function: tup_removemid
Description: Removes from the beginning of tuple
Used as: a = tup_removemid(lista, number)
Notes: Same as tup_removemid. Does not edit in place.
Works on list, tuples, strings.
'''
output_list = lista[:numberstart] + lista[numberend+1:]
return output_list
a = 'panagosasdasdasd'
b = [ 1, 2, 3, 4, "x", 5, 3, 2, 7, 6 ]
c = ( 1, 2, 3, 6, 4, 3, 2,)
print (list_removemid(b, 1, 4))
print (list_removemid(a, 1, 3))
print (list_removemid(c, 2, 5))
def list_removeend(lista, number):
'''
Function: tup_removeend
Description: Removes from the beginning of tuple
Used as: a = tuple_removeend(lista, number)
Notes: Same as tuple_removeend. Does not edit in place.
Works on list, tuples, strings.
'''
lengthof = len(lista)
calc = lengthof - number
output_list = lista[:calc]
return output_list
a = 'panagosasdasdasd'
b = [ 1, 2, 3, 4, "x", 5, 3, 2, 7, 6 ]
c = ( 1, 2, 3, 6, 4, 3, 2,)
#print (list_removeend(a, 1))
#print (list_removeend(b, 2))
#print (list_removeend(c, 1))
def tup_removebeg(lista, number):
'''
Function: tup_removebeg
Description: Removes from the beginning of tuple
Used as: a = tuple_removebeg(lista, number)
Notes: Same as tuple_removebeg. Does not edit in place.
Works on list, tuples, strings.
'''
output_list = lista[number:]
return output_list
a = 'panagosasdasdasd'
b = [ 1, 2, 3, 4, "x", 5, 3, 2, 7, 6 ]
c = ( 1, 2, 3, 6, 4, 3, 2,)
#print (list_removebeg(a, 2))
#print (list_removebeg(b, 3))
#print (list_removebeg(c, 1))
def listtotuple(list):
'''
Function : listtotuple
Description : Transforms list to tuple
Input : list
Output: tuple
Usage : a = listtotuple(tuple)
Note :
'''
out = ()
for j in list:
out += (j,)
return out
1. revtuple : Reverse a tuple
2. rdupl_tupl : Remove duplicate elements from a tuple
3. tuple2list : Converts a tuple to list
4. tupletostring : Converts a tuple to string
5. listtotuple : Converts a list into a tuple
6. strtotuple : Converts a string into a tuple
7. tup_removebeg : Removes elements from the beginning of a tuple
8. tup_removeend : Removes elements from the end of a tuple
9. tup_removemid : Removes elements from the mid of a tuple
def rdupl_tuple(tuplea):
'''
Function : rdupl_tuple
Description : Removes duplicates in a tuple
Input : tuple
Output: tuple with unique elements
Usage : a = rdupl_tuple(tuple)
Notes : Does not edit in place
'''
outtuple = ()
seenlist = []
for i in tuplea:
if i not in seenlist:
seenlist.append(i)
outtuple = outtuple + (i,)
return outtuple
def tupletostr(tuple):
out = ''
for x in tuple:
out = out + str(x)
return out
print (tupletostr(a))
def tuple2list(tuple):
'''
Function : tuple2list
Description : Converts a tuple into a list
Inputs : Tuple
Output : List
Usage(print): print (tuple2list(tuple))
Usage(Assign): b = tuple2list(tuple))
'''
outlist = []
for j in tuple:
outlist.append(j)
return outlist
def strtotuple(string):
out = ()
for s in string:
out = out + (s,)
return out
def reverse_tuple(tup):
'''
Function : reverse_tuple
Description : Reverses a tuple
Input : tuple
Output : tuple with reversed elements
Usage : a = reverse_tuple(tuple)
Notes : Does not edit in place
'''
outtupe = ()
for i in tup:
outtupe = (i,) + outtupe
return outtupe