• pre-exam_exercise2


    def rearrange(L,from_first=True):
        new_list=[]
        if from_first:
            for i in range(int(len(L)/2)):
                new_list.append(L[i])
                new_list.append(L[-i-1])
            if len(L)%2!=0:
                new_list.append(L[int(len(L)/2)])
        else:
            for i in range(int(len(L)/2)):
                new_list.append(L[-i-1])
                new_list.append(L[i])
            if len(L)%2!=0:
                new_list.append(L[int(len(L)/2)])
        return new_list
    
    answer=rearrange(L=[10,20,30,40,50],from_first=False)
    print(answer)

    Returns a new list consisting of:

    * in case "from_first" is True:

    L’s first member if it exists, then L’s last member if it exists, then L’s second member if it exists, then L’s second last member if it exists, then L’s third member if it exists...

    * in case "from_first" is False:

    L’s last member if it exists, then L’s first member if it exists, then L’s second last member if it exists, then L’s second member if it exists, then L’s third last member if it exists...

  • 相关阅读:
    【php】错误日志处理
    【php】正则表达式
    【php】字符串
    【PHP】数组
    【PHP】函数
    【PHP】流程控制
    【PHP】PHP运算符
    【PHP】PHP基本语法
    【前端】CSS总结
    SVN与Apache整合
  • 原文地址:https://www.cnblogs.com/eleni/p/11251455.html
Copyright © 2020-2023  润新知