#!/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. Java中数据类型的分类

    我们知道Java是强类型语言,那么肯定对应的也就有弱类型语言,以下介绍强类型语言与弱类型语言的区别: 强类型语言: 强类型语言也就是强制数据类型定义的语言.也就是说,一旦一个变量被指定了某个数据类型, ...

  2. javascript事件触发器fireEvent和dispatchEvent

    javascript事件触发器fireEvent和dispatchEvent   事件触发器就是用来触发某个元素下的某个事件,IE下fireEvent方法,高级浏览器(chrome,firefox等) ...

  3. 关于ftp用户连接时出现500OOPS:can not change directory的解决办法

    今天在使用Filezilla连接Linux的时候不能成功,显示"500 OOPS:cannot change directory:/root" 错误,如何解决呢? 默认下是没有开启 ...

  4. struts2 中的 addActionError 、addFieldError、addActionMessage方法的区别添加错误信息

    转自:https://www.cnblogs.com/wangyp/archive/2011/07/13/2104828.html 一.addActionError("错误内容") ...

  5. 基于celery的任务管理

    1.celery基本原理 Celery是一个由python编写的简单.灵活.可靠的用来处理大量信息的分布式系统,同时提供了操作和维护分布式系统所需要的工具,说白了就是一个用来管理分布式队列的工具. C ...

  6. 树——minimum-depth-of-binary-tree(二叉树的最小深度)

    问题: Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the s ...

  7. js实时计算价格

    //通过数量,单价的输入,实时显示总价 $("#number,#price").on("input",function(e){ $("#totalPr ...

  8. [python 学习]正则表达式

    re 模块函数re 模块函数和正则表达式对象的方法match(pattern,string,flags=0) 尝试使用带有可选的标记的正则表达式的模式来匹配字符串.如果匹配成功,就返回匹配对象:如果失 ...

  9. Intellij IDEA 插件开发秘籍

    来这里找志同道合的小伙伴! 这里总结一下 Intellij IDEA 插件开发的知识,供大家参考,本篇文章包含以下内容: 开发环境搭建 Component 介绍 Extension Point And ...

  10. java8-Stream集合操作快速上手

    java8-Stream集合操作快速上手   目录 Stream简介 为什么要使用Stream 实例数据源 Filter Map FlatMap Reduce Collect Optional 并发 ...