#Say I have the lists
l1 = [2,3,6,7,9]
l2 = [11,14,16,20,21]
# and a random number, say 8
x = 8
# And I want to change l1 so that if there is any number larger than
# 8 it will be deleted, then 8 will be inserted into the end of l1
# the output would look like this: [2,3,6,7,8]
# And I want to change l2 so that if there is any number smaller than
# 8 it will be deleted, then 8 will be inserted into the beginning of l2
# the output would look like this: [8,11,14,16,20,21]
我不知道如何去解決這個問題,並真誠感謝您的幫助。謝謝!將元素添加到列表中的特定位置
我知道我應該使用if語句來刪除元素,並且我可以使用append函數將8放入列表中。但是,我不確定是否有更簡單的方法。 – PiccolMan