类别归档:Python

Python is a programming language that lets you work quickly and integrate systems more effectively.

RSS feed of Python

[Leetcode]Reverse Words in a String

题目描述

Given an input string, reverse the string word by word.

For example,
Given s = "the sky is blue",
return "blue is sky the".

Clarification:

What constitutes a word?
A sequence of non-space characters constitutes a word.

Could the ...

继续阅读

[LeetCode]Maximum Product Subarray

题目描述:

Find the contiguous subarray within an array (containing at least one number) which has the largest product.

For example, given the array [2,3,-2,4],
the contiguous subarray [2,3] has the largest product = 6.

题目大意:

从数组(至少包含一个数字)中找出一个连续的子数组,该子数组的乘积最大。

解题思路:

    简单动态规划: ...

继续阅读

Python脚本如何生成Windows可执行文件.exe

Python是一种简单而强大的编程语言,适用于编写脚本,甚至于应用程序的开发。Python可用的各种GUI包使得利用Python编写全功能的应用变为可能。这很好,但你有没有想过将你编写的Python脚本转化为可执行文件?这似乎是一个很赞的主意,有许多原因!你可以在没有Python解释器的情况下重新部署你的应用。终端用户不需要在他的机器上安装Python。你可以将你的应用闭源(很不幸)等等……这篇文章可以告诉你如何从你的Python脚本生成win32可执行文件。 

Python is a simple and powerful language for scripting and even application development. Various GUI packages available for Python makes it suitable for developing full fledged applications in python. Ok that is fine, but ever thought of creating an ...

继续阅读

pyquery:一个类似于jquery的Python库

pyquery:一个类似于jquery的Python库

pyquery可以使你在xml文档上做jquery查询,它的API尽可能地类似于jquery。pyquery使用lxml执行快速的xml和html操作。

这并非(至少目前还不是)一个生成javascript代码或者与javascript代码做交互的库。pyquery的作者只是由于非常喜欢jquery的API因而将其用python实现。

该项目目前托管在Github仓库中并且处于活跃开发状态。作者可以为任何想要贡献源码的开发者赋予push权限,并且会对其做的变更做回顾。如果你想要贡献源码,可以发Email给项目作者。

项目的Bug可以通过Github Issue Tracker进行提交。

快速入门

你可以使用PyQuery类从一个字符串,一个lxml文档,一个文件或者一个url钟载入一个xml文档:

>>> from pyquery import PyQuery as pq
>>> from lxml import etree
>>> import urllib
>>> d = pq("<html></html>")
>>> d = pq(etree.fromstring("<html></html>"))
>>> d = pq(url=your_url)
>>> d = pq(url=your_url, ...

继续阅读