The Zen of Python
1 | Beautiful is better than ugly. |
Easter Egg
1 | >>> import this |
1 | Beautiful is better than ugly. |
1 | >>> import this |
What important thing did King Alfred learn when he penetrated the Danish camp of Guthrum?
Alfred the Great acted his own spy, visiting Danish camps disguised as a minstrel. In those days wandering minstrels were welcome everywhere. They were not fighting men, and their harp was their passport. Alfred had learned many of their ballads in his youth, and could vary his programme with acrobatic tricks and simple conjuring.
While Alfred’s little army slowly began to gather at Athelney, the king himself set out to penetrate the camp of Guthrum, the commander of the Danish invaders. There had settled down for the winter at Chippenham: thither Alfred went. He noticed at once that discipline was slack: the Danes had the self-confidence of conquerors, and their security precautions were casual. They lived well, on the proceeds of raids on neighbouring regions. There they collected women as well as food and drink, and a life of ease had made them soft.
What makes trading between rich countries difficult?
Chickens slaughtered in the United States, claim officials in Brussels, are not fit to grace European tables. No, say the American: our fowl are fine, we simply clean them in a different way. These days, it is differences in national regulations, far more than tariffs, that put sand in the wheels of trade between rich countries. It is not just farmers who are complaining. An electric razor that meets the European Union’s safety standards must be approved by American testers before it can be sold in the United States, and an American-made dialysis machine needs the EU’s okay before is hits the market in Europe.
As it happens, a razor that is safe in Europe is unlikely to electrocute Americans. So, ask businesses on both sides of the Atlantic, why have two lots of tests where one would do? Politicians agree, in principle, so America and the EU have been trying to reach a deal which would eliminate the need to double-test many products. They hope to finish in time for a trade summit between America and the EU on May 28TH. Although negotiators are optimistic, the details are complex enough that they may be hard-pressed to get a deal at all.
Why? One difficulty is to construct the agreements. The Americans would happily reach one accord on standards for medical devices and then hammer out different pacts covering, say, electronic goods and drug manufacturing. The EU—following fine continental traditions—wants agreement on general principles, which could be applied to many types of products and perhaps extended to other countries.
In what way does echo-location in bats play an utilitarian role?
Not all sounds made by animals serve as language, and we have only to turn to that extraordinary discovery of echo-location in bats to see a case in which the voice plays a strictly utilitarian role.
To get a full appreciation of what this means we must turn first to some recent human inventions. Everyone knows that if he shouts in the vicinity of a wall or a mountainside, an echo will come back. The further off this solid obstruction, the longer time will elapse for the return of the echo. A sound made by tapping on the hull of a ship will be reflected from the sea bottom, and by measuring the time interval between the taps and the receipt of the echoes, the depth of the sea at that point can be calculated. So was born the echo-sounding apparatus, now in general use in ships. Every solid object will reflect a sound, varying according to the size and nature of the object. A shoal of fish will do this. So it is a comparatively simple step from locating the sea bottom to locating a shoal of fish. With experience, and with improved apparatus, it is now possible not only to locate a shoal but to tell if it is herring, cod, or other well-known fish, by the pattern of its echo.
It has been found that certain bats emit squeaks and by receiving the echoes, they can locate and steer clear of obstacles—or locate flying insects on which they feed. This echo-location in bats is often compared with radar, the principle of which is similar.
原文:
Not all sounds made by animals serve as language, and we have only to turn to that extraordinary discovery of echo-location in bats to see a case in which the voice plays a strictly utilitarian role.
结构分析:
1 | 主句1: Not all sounds ... serve as language |
逐词翻译:
参考译文:
并非所有动物发出的声音都具有语言功能,我们只需看看蝙蝠回声定位这一非凡发现,就能明白声音在某些情况下纯粹起着实用性作用。
翻译要点:
原文:
Everyone knows that if he shouts in the vicinity of a wall or a mountainside, an echo will come back.
结构分析:
1 | 主句: Everyone knows that... |
逐词翻译:
参考译文:
每个人都知道,如果在墙壁或山坡附近大喊,就会听到回声返回。
原文:
A sound made by tapping on the hull of a ship will be reflected from the sea bottom, and by measuring the time interval between the taps and the receipt of the echoes, the depth of the sea at that point can be calculated.
结构分析:
1 | 第一部分: |
逐词翻译:
参考译文:
敲击船体发出的声音会从海底反射回来,通过测量敲击声和接收回声之间的时间间隔,就可以计算出该处的海水深度。
翻译技巧:
原文:
So was born the echo-sounding apparatus, now in general use in ships.
结构分析:
1 | 倒装句: So was born the apparatus |
逐词翻译:
参考译文:
回声测深仪就这样诞生了,现在已在船舶上普遍使用。
语法点:
原文:
Every solid object will reflect a sound, varying according to the size and nature of the object.
结构分析:
1 | 主句: Every solid object will reflect a sound |
逐词翻译:
参考译文:
每个固体物体都会反射声音,反射效果因物体的大小和性质而异。
翻译技巧:
原文:
So it is a comparatively simple step from locating the sea bottom to locating a shoal of fish.
结构分析:
1 | 主语: it (形式主语) |
逐词翻译:
参考译文:
因此,从定位海底到定位鱼群,这是一个相对简单的进步。
原文:
With experience, and with improved apparatus, it is now possible not only to locate a shoal but to tell if it is herring, cod, or other well-known fish, by the pattern of its echo.
结构分析:
1 | 状语1: With experience |
逐词翻译:
参考译文:
凭借经验和改进的设备,现在不仅可以定位鱼群,还可以通过回声的模式来判断是鲱鱼、鳕鱼还是其他常见鱼类。
翻译难点:
原文:
It has been found that certain bats emit squeaks and by receiving the echoes, they can locate and steer clear of obstacles—or locate flying insects on which they feed.
结构分析:
1 | 主句: It has been found that... |
逐词翻译:
参考译文:
研究发现,某些蝙蝠会发出尖叫声,通过接收回声,它们可以定位并避开障碍物——或者定位它们捕食的飞行昆虫。
翻译要点:
原文:
This echo-location in bats is often compared with radar, the principle of which is similar.
结构分析:
1 | 主句: This echo-location is compared with radar |
逐词翻译:
参考译文:
蝙蝠的这种回声定位常被拿来与雷达相比较,两者的原理相似。
| 技巧 | 例句 | 说明 |
|---|---|---|
| 部分否定 | Not all sounds | 译为”并非所有”而非”所有都不” |
| 后置定语前置 | sounds made by animals | 译为”动物发出的声音” |
| 倒装句还原 | So was born… | 强调”诞生”,译时可还原语序 |
| 分词短语处理 | varying according to | 译为”因…而异” |
| 形式主语转换 | it is possible to… | 可直接译为”可以…” |
How does the writer describe sport at the international level?
I am always amazed when I hear people saying that sport create goodwill between nations, and that if only the common peoples of the world could meet one another at football or cricket, they would have no inclination to meet on the battle field. Even if one didn’t know from concrete examples (the 1936 Olympic Games, for instance) that international sporting contests lead to orgies of hatred, one could deduce it from general principles.
Nearly all the sports practised nowadays are competitive. You play to win, and the game has little meaning unless you do your utmost to win. On the village green, where you pick up sides and no feeling of local patriotism is involved, it is possible to play simply for the fun and exercise: but as soon as the question of prestige arises, as soon as you feel that you and some larger unit will be disgraced if you lose, the most savage combative instincts are aroused. Anyone who has played even in a school football match knows this. At the international level, sport is frankly mimic warfare. But the significant thing is not the behavior of the players but the attitude of the spectators; and, behind the spectators, of the nations who work themselves into feries over these absurd contests, and seriously believe—at any rate for short periods—that running, jumping and kicking a ball are tests of national virtue.
I am always amazed when I hear people saying that sport create goodwill between nations, and that if only the common peoples of the world could meet one another at football or cricket, they would have no inclination to meet on the battle field.
每当我听到人们说体育能在国家之间创造友好关系,说如果世界各国的普通民众能在足球场或板球场上相遇,他们就不会有意愿在战场上相见时,我总是感到惊讶。
Even if one didn’t know from concrete examples (the 1936 Olympic Games, for instance) that international sporting contests lead to orgies of hatred, one could deduce it from general principles.
即使人们不知道具体的例子(比如1936年奥运会),不知道国际体育比赛会导致仇恨的狂欢,也可以从一般原理中推断出这一点。
Nearly all the sports practised nowadays are competitive. You play to win, and the game has little meaning unless you do your utmost to win.
如今实行的几乎所有体育运动都是竞技性的。你参赛是为了获胜,除非你全力以赴去赢,否则比赛就没什么意义。
On the village green, where you pick up sides and no feeling of local patriotism is involved, it is possible to play simply for the fun and exercise:
在乡村草地上,你随意分组,不涉及任何地方爱国主义情感时,确实可能只是为了娱乐和锻炼而比赛:
but as soon as the question of prestige arises, as soon as you feel that you and some larger unit will be disgraced if you lose, the most savage combative instincts are aroused.
但一旦涉及声誉问题,一旦你感到如果输了,你和你所代表的某个更大群体将蒙受耻辱,最野蛮的好斗本能就会被激发出来。
Anyone who has played even in a school football match knows this.
任何参加过哪怕只是校园足球比赛的人都知道这一点。
At the international level, sport is frankly mimic warfare.
在国际层面,体育坦率地说就是模拟战争。
But the significant thing is not the behavior of the players but the attitude of the spectators;
但重要的不是运动员的行为,而是观众的态度;
and, behind the spectators, of the nations who work themselves into furies over these absurd contests,
而在观众背后,是那些为这些荒谬的竞赛让自己陷入狂怒的国家,
and seriously believe—at any rate for short periods—that running, jumping and kicking a ball are tests of national virtue.
并且认真地相信——至少在短时间内——跑步、跳跃和踢球是对民族美德的考验。
1 | 理想观点:体育促进和平 |
| 表面 | 深层 |
|---|---|
| 体育比赛 | 民族主义 |
| 观众狂热 | 集体非理性 |
| 竞技精神 | 战争思维 |
I am always amazed when…
as soon as… the most savage instincts are aroused
frankly speaking / to be frank
work oneself into…
总结:这是一篇犀利的批判性散文,作者通过层层递进的论证,揭示了国际体育背后的民族主义本质,文笔辛辣,论证有力,是经典的议论文范本。🎯
How does the writer like to treat young people?
People are always talking about ‘the problem of youth’. If there is one — which I take leave to doubt — then it is older people who create it, not the young themselves. Let us get down to fundamentals and agree that the young are after all human beings — people just like their elders. There is only one difference between an old man and a young one: the young man has a glorious future before him and the old one has a splendid future behind him: and maybe that is where the rub is.
When I was a teenager, I felt that I was just young and uncertain — that I was a new boy in a huge school, and I would have been very pleased to be regarded as something so interesting as a problem. For one thing, being a problem gives you a certain identity, and that is one of the things the young are busily engaged in seeking.
I find young people exciting. They have an air of freedom, and they have not a dreary commitment to mean ambitions or love of comfort. They are not anxious social climbers, and they have no devotion to material things. All this seems to me to link them with life, and the origins of things. It’s as if they were, in some sense, cosmic beings in violent and lovely contrast with us suburban creatures. All that is in my mind when I meet a young person. He may be conceited, ill-mannered, presumptuous or fatuous, but I do not turn for protection to dreary cliches about respect for elders — as if mere age were a reason for respsect. I accept that we are equal, and I will argue with him, as an equal, if I think he is wrong.
1 | 引言:驳斥"青年问题" |
“People are always talking about ‘the problem of youth’. If there is one—which I take leave to doubt—then it is older people who create it, not the young themselves.”
解析:
“Let us get down to fundamentals and agree that the young are after all human beings—people just like their elders.”
解析:
“There is only one difference between an old man and a young one: the young man has a glorious future before him and the old one has a splendid future behind him: and maybe that is where the rub is.”
解析:
“When I was a teenager, I felt that I was just young and uncertain—that I was a new boy in a huge school…”
解析:
“…and I would have been very pleased to be regarded as something so interesting as a problem.”
解析:
“For one thing, being a problem gives you a certain identity, and that is one of the things the young are busily engaged in seeking.”
解析:
“I find young people exciting.”
解析:
“They have an air of freedom, and they have not a dreary commitment to mean ambitions or love of comfort.”
解析:
“They are not anxious social climbers, and they have no devotion to material things.”
解析:
“All this seems to me to link them with life, and the origins of things.”
解析:
“It’s as if they were, in some sense, cosmic beings in violent and lovely contrast with us suburban creatures.”
解析:
| 年轻人 | 老年人 |
|---|---|
| cosmic beings(宇宙生命) | suburban creatures(郊区生物) |
| 广阔、自由、本真 | 狭隘、世俗、平庸 |
violent and lovely contrast = 激烈而美好的对比
suburban 的隐喻:
“All that is in my mind when I meet a young person.”
解析:
“He may be conceited, ill-mannered, presumptuous or fatuous…”
解析:
“…but I do not turn for protection to dreary clichés about respect for elders—as if mere age were a reason for respect.”
解析:
核心观点: 年龄本身不值得尊重,值得尊重的是人品和智慧
“I accept that we are equals, and I will argue with him, as an equal, if I think he is wrong.”
解析:
三次强调”equal”(平等):
argue 的积极含义:
| 对比项 | 年轻人 | 老年人 |
|---|---|---|
| 时间维度 | 未来在前 | 过去在后 |
| 生活态度 | 自由、理想主义 | 功利、物质主义 |
| 存在状态 | 宇宙生命 | 郊区生物 |
| 对比效果 | violent & lovely | dreary & mean |
“It is older people who create it, not the young themselves.”
“Being a problem gives you a certain identity.”
“As if mere age were a reason for respect.”
“Cosmic beings in violent and lovely contrast with suburban creatures.”
这篇文章是一篇关于代际关系的哲理散文,作者通过:
最终传达的核心价值观:
真正的尊重不是基于年龄,而是基于平等的人格;年轻人的价值不在于完美,而在于生命力和可能性。
Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that all its elements lies in [L, R] (R >= L). You might need to change the root of the tree, so the result should return the new root of the trimmed binary search tree.
Example 1:
1 | Input: |
Example 2:
1 | Input: |
Easy
采用递归的方法。如果root为空,则直接返回root; 如果root的值<L,表示root及其左子树所有节点都<L,那么需要改变root节点,从root.right中重新寻找root节点。同理,当root的值>R时,需要从root.left中重新寻找root节点。当L<=root.val<=R时,则递归处理root的左右子树。
1 | class TreeNode(object): |
晚上11点前睡,你能做到吗?
前几天,北京大学法学院2017迎新典礼上,白建军教授给新生的建议火遍全网:“早睡早起+把微信朋友圈控制在10人以内+拒绝以陪读为目的的表白。这个办法能不能把你弄成精英中的精英,我不知道。但试过的,都说好。”
这3条建议中,我试过“早睡早起”这一条。抓住早睡这个突破点后,早起也能轻松上手,投资小,回报大,性价比高。
但我观察周围,这大约是个年轻人全民熬夜的年代。有人工作分工没办法,有人夜晚干活效率高,有人单纯性晚睡拖延症。许多人在睡觉方面缺乏自制力,晚上不想睡,手机像长在手上似的;早上起不来,醒来就跟闹钟置气,一天到晚觉得困。
原来在我们这个时代,早睡早起,真的变成了最知易行难的自律。
虽然网上不时会曝出因为熬夜导致健康受损甚至猝死的案例,不管当事人如何苦口婆心地劝诫一定要规律作息,千万不要熬夜,可还是有许多人会说,道理我们都知道的,可就是忍不住熬夜啊。
以前我在深圳工作时,有段时间早上五点多就起床,去附近的荔香公园快走。我发现这个时段公园里老年人的密度极高,他们神采奕奕地进行着做操、跑步、挥鞭等各种锻炼。
而我看到年轻人密度最高的时段是晚上。我有时加班到晚上十点多,在赶回家睡觉的路上,看到写字楼里还有大片灯光,商场周围还有K歌聚会,便利店里还有人进人出。
这好像一幕滑稽戏,早睡早起的老年人和晚睡晚起的年轻人,处于不同的时区。结果,老年人状态越来越燃,年轻人却越活越没精神。
其实,早睡早起,是性价比最高的自律。
前东家大领导30多岁那年,大病一场之后,作息习惯大换血,他把工作模式从没日没夜改为早睡早起,工作绩效不减反增;
我婶婶婚后越长越好看,随着年纪增长,她的皮肤却比初见时细腻白嫩了很多,她说因为自己单身时熬的夜,结婚后都戒了;
我早上五点多去公园的事迹被同事们听说后,都叉着腰笑我过着老年人的生活,可我那时的工作效率和身体状态都处于巅峰级别。
我最近采访了一位服装品牌的女创始人。采访前,我没想到作为一个张罗创业公司大小业务、高频参加品牌活动和电视节目、照顾一儿一女起居饮食的妈妈,竟然这么活力四射、声音带感。
我掘地三尺地问她如何保持这么赞的状态,她归因为早睡早起,作息规律。
她告诉我,她之前刚生完孩子那阵,起夜奶娃导致睡不好觉,眼圈深黑、披头散发,整天抱着负面情绪的洋快餐在啃啊啃。
这几年,她的生活质量因睡眠改善而改头换面。她晚上八九点把小儿子哄睡,然后接着给大女儿讲睡前故事,通常女儿还没睡着,她倒先催眠了自己。
晚上九点十点就入睡,第二天早上七点起床,能最大限度地保证自己电力满格。
同一个人的两个对照组也证明,每天这种早睡早起的节律感,能让人心情愉悦,办事高效。但凡是眼不拙的人,都能看出老天在打赏敬重生物钟的人。
以前,一位文笔有灵气的女作者,她白天上班,晚上写作,每次看她公众号的更文时间都很心疼她。
她做任何工作,业绩都要拼到极致,任何吃穿用度都要用到最好,晚上一两点才睡是常态,生病了还边打吊瓶边写作。在她的一篇文章里,她悲情地说自己掉发严重、记性变差,怀疑自己会早早死掉。
我不看好这种“自毁式的勤奋”,这哪是鸡血,分明是狗血。我多希望她能把晚睡晚起置换成早睡早起,在工作时长差不多的情况下,把对身体的伤害降至最低。
以保重身体为前提的努力,是一种远见。
我热爱写作,也想长久写作,所以,榜样都是精力足以撑起终生写作的人。比如村上春树,对于小说家及其创作而言,他认为最重要的就是集中力和耐力。这就是他早睡早起、朝五晚九、规律生活、坚持跑步的原因,是为了身体好,有体力,以便能有写一本书的能量。
日本另一位高产优产的作家松浦弥太郎,也在书中写过早睡早起、作息规律的重要性。他说:每天晚上十点左右上床,早上五点起床,每隔一天要去锻炼,快走十公里,然后八点去上班。这种规律性的生活对于我来说,是非常重要的工作之一。
健康管理是最重要的工作。有规律地生活,是做好一切的最基本要求。时刻保持旺盛的精力,这也是获得信任的第一步。
如果你有心追求事业,热爱生活,深爱家人,那么一定要把健康当成顶层设计,挂起晚睡的战靴,远离手机这类晚睡培养皿,第二天早点起来提升或运动。
我始终相信,早睡早起身体好。而身体好的人,才有一切的选择权和被选择权。
来源:哪梁爽哪喜庆(ID: zheliangshuang) | 作者: 梁爽 | 平台: 新浪微博
Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a circle, which means it moves back to the original place.
The move sequence is represented by a string. And each move is represent by a character. The valid robot moves are R(Right), L(Left), U(Up) and D(down). The output should be true or false representing whether the robot makes a circle.
Example 1:
1 | Input: "UD" |
Example 2:
1 | Input: "LL" |
Easy
对每个方向计数,如果L出现的次数==R出现的次数,并且U出现的次数==D出现的次数,则robot会回到初始位置,返回True;否则返回False
1 | class Solution(object): |
Given a non-empty special binary tree consisting of nodes with the non-negative value, where each node in this tree has exactly two or zero sub-node. If the node has two sub-nodes, then this node’s value is the smaller value among its two sub-nodes.
Given such a binary tree, you need to output the second minimum value in the set made of all the nodes’ value in the whole tree.
If no such second minimum value exists, output -1 instead.
Example 1:
1 | Input: |
Example 2:
1 | Input: |
Easy
首先将最小值minimum和第二小值second_minimum置为maxint,递归遍历二叉树,如果节点值比最小值小,则将最小值赋给第二小值,然后将最小值更新为节点值;如果节点值比最小值大,并且节点值小于第二小值,则将第二小值更新为节点值。节点遍历后如果第二小值==maxint,即没有第二小值,则返回-1
1 | import sys |