migration from cloud service
This commit is contained in:
33
week4/ex4.py
Normal file
33
week4/ex4.py
Normal file
@@ -0,0 +1,33 @@
|
||||
def main():
|
||||
from random import randint
|
||||
print('==Exercise 4==')
|
||||
LIST_A = [1,2.0,'c',{"id":4}]
|
||||
LIST_B = [randint(1,100) for i in range(10)]
|
||||
LIST_C = [*[chr(i+65) for i in range(10)],27,28.0]
|
||||
|
||||
print('Lists Initial Values:')
|
||||
print(f'{i["idtf"]}: {i["value"]}' for i in [
|
||||
{"idtf":"List A","value":LIST_A},
|
||||
{"idtf":"List B","value":LIST_B},
|
||||
{"idtf":"List C","value":LIST_C},
|
||||
])
|
||||
|
||||
print('a range of items: ',LIST_C[:-3])
|
||||
print('reverse print of list: ',LIST_C[::-1])
|
||||
|
||||
popped_item = LIST_C.pop(3)
|
||||
print(f'Deleted 4th item(index=3)={popped_item} from list C: {LIST_C}')
|
||||
|
||||
LIST_C.insert(5,LIST_A)
|
||||
print(f'Insert items from list A to list C start from pos5(index=4): {LIST_A}')
|
||||
|
||||
LIST_B.sort()
|
||||
print('sorting List B:',LIST_B)
|
||||
|
||||
print('number of similar items in the list B: ',sum([1 if LIST_B[i] in LIST_B[i+1:] else 0 for i in range(len(LIST_B))]))
|
||||
|
||||
print('==End Of Ex4==')
|
||||
return 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user