#!/usr/bin/python
#coding:utf-8 ten_things = "apples oranges crows telephone light sugar"
print "wait there's not 10 things in that list,let's fix that" stuff = ten_things.split(' ') #10个东西,以' '间隔开
more_stuff = ["day","night","song","frisbee","corn","banana","girl","boy"] #更多的原料 while len(stuff) != 10: #取得List stuff的长度,当不等于10时循环
next_one = more_stuff.pop() #截取more_stuff的最后一个元素(默认值)
print "adding:",next_one #输出pop取得的值
stuff.append(next_one) #使用append将之前截取的值赋予list:stuff
print "there's %d items now" % len(stuff) print "there we go : ",stuff print "let's do some things with stuff" print stuff[1] #第二个元素,list从0计数
print stuff[-1] #whoa!fancy 最后一个元素(-1)
print stuff.pop()
print ' '.join(stuff) #what?cool!
print '#'.join(stuff[3:5]) # super stellar

Output:

 wait there's not 10 things in that list,let's fix that
adding: boy
there's 7 items now
adding: girl
there's 8 items now
adding: banana
there's 9 items now
adding: corn
there's 10 items now
there we go : ['apples', 'oranges', 'crows', 'telephone', 'light', 'sugar', 'boy', 'girl', 'banana', 'corn']
let's do some things with stuff
oranges
corn
corn
apples oranges crows telephone light sugar boy girl banana
telephone#light

join()

加分题的一些参考: Python 面向对象编程 函数式编程

Learn Python the hard way, ex39 列表的操作的更多相关文章

  1. learn python the hard way习题31~40总结以及列表的扩展知识

    Python 中的列表: 形式:[ 表示打开一个列表,中间的项目用 , 隔开,然后列表以 ] 结束. for循环 两种形式: for i in ArrayName: for i in range(0, ...

  2. [IT学习]Learn Python the Hard Way (Using Python 3)笨办法学Python3版本

    黑客余弦先生在知道创宇的知道创宇研发技能表v3.1中提到了入门Python的一本好书<Learn Python the Hard Way(英文版链接)>.其中的代码全部是2.7版本. 如果 ...

  3. 笨办法学 Python (Learn Python The Hard Way)

    最近在看:笨办法学 Python (Learn Python The Hard Way) Contents: 译者前言 前言:笨办法更简单 习题 0: 准备工作 习题 1: 第一个程序 习题 2: 注 ...

  4. 学 Python (Learn Python The Hard Way)

    学 Python (Learn Python The Hard Way) Contents: 译者前言 前言:笨办法更简单 习题 0: 准备工作 习题 1: 第一个程序 习题 2: 注释和井号 习题 ...

  5. python学习04——列表的操作

    笨办法学python第38节 如何创建列表在第32节,形式如下: 本节主要是讲对列表的操作,首先讲了 mystuff.append('hello') 的工作原理,我的理解是,首先Python找到mys ...

  6. Python内建的对象列表

    Python内建的对象列表 刚写Python肯定会遇到这样的情况,想写些什么,但又不知从何写起... 在我看来问题在于我们不知道有什么东东可以拿来玩,这里列出Python的内建对象,稍微归类了一下,多 ...

  7. python数据类型详解及列表字典集合推导式详解

    一.运算符 Python语言支持以下类型的运算符: 算术运算符 如: #!/usr/bin/env python # -*- coding:utf-8 -*- a = 5 b = 6 print(a ...

  8. Python基础:序列(列表、元组)

    一.概述 列表(list)是由一个个 Python对象 组成的序列.其中,Python对象 可以是任何类型的对象,包括 Python标准类型(数值.字符串.列表.元组和字典)以及 用户自定义类型(类) ...

  9. python【第二篇】列表、元组、字典及文件操作

    本节内容 列表 元组操作 字符串操作 字典操作 集合操作 文件操作 字符编码与转码 1.列表 列表是我们最以后最常用的数据类型之一,通过列表可以对数据实现最方便的存储.修改等操作:列表有序.可变.元素 ...

随机推荐

  1. BZOJ 1875(DP+矩阵快速幂)

    题面 传送门 分析 容易想到根据点来dp,设dp[i][j]表示到i点路径长度为j的方案数 状态转移方程为dp[i][k]=∑(i,j)∈Edp[j][k−1]" role="pr ...

  2. win32 socket 编程(三)——TCP/IP

    一.TCP/IP解析 TCP/IP协议的核心部分是传输层协议(TCP.UDP),网络层协议(IP)和物理接口层,这三层通常是在操作系统内核中实现.因此用户一般不涉及.编程时,编程界面有两种形式: 1. ...

  3. IIS环境下PHP版本过低无法Sql查询的解决

    需求:帝国后台添加个后台框,输入地址,原页面重写成所指链接页面 重点:当输入框输入地址,提交到后台后,打开原链接,该页面会读取php文件GetUrlPage.php <?php header(& ...

  4. 关键字static介绍

    static关键字 java中针对多个对象有共同的成员变量值得时候,就提供了static关键字来修饰. (1)静态的意思.可以修饰成员变量和成员方法. (2)静态的特点: A:随着类的加载而加载 B: ...

  5. 学Python的第四天

    第四天啦,今天依旧代码少的啃树皮.... 但是作业留的有了幼儿园的水准!!!让小编我看到了希望.... #!/usr/bin/env python # -*- coding:utf8 -*- impo ...

  6. How to compile and install Linux Kernel 5.1.2 from source code

    How to compile and install Linux Kernel 5.1.2 from source code Compiling a custom kernel has its adv ...

  7. numpy中tile的用法

    a=arange(1,3) #a的结果是: array([1,2]) 1,当 tile(a,1) 时: tile(a,1) #结果是 array([1,2]) tile(a,2) #结果是 array ...

  8. 12JDBC

    1.JDBC概述 JDBC(Java Data Base Connectivity,java数据库连接)是一种用于执行SQL语句的Java API,可以为多种关系数据库提供统一访问,它由一组用Java ...

  9. alert(1) to win

    一. function escape(s) { return '<script>console.log("'+s+'");</script>'; } 两种思 ...

  10. python tkinter实时显示曲线

    from tkinter import *from tkinter import ttkimport time#画窗口root = Tk()root.geometry('1000x500')root. ...