我正在检查是否有两个字符串a
并且b
是彼此的排列,我想知道在Python中执行此操作的理想方法是什么.从Python的禅宗,"应该有一个 - 最好只有一个 - 显而易见的方式",但我看到至少有两种方式:
sorted(a) == sorted(b)
Run Code Online (Sandbox Code Playgroud)
和
all(a.count(char) == b.count(char) for char in a)
Run Code Online (Sandbox Code Playgroud)
但是第一个是慢的时候(例如)第一个char a
无处可去b
,而第二个是实际排列时更慢.
有更好的方法(无论是更多的Pythonic,还是平均更快的意义上)的方式呢?或者我应该从这两个中选择,具体取决于我期望最常见的情况?
我想在通知栏中放置一个进度条.当程序将文件上传到服务器时,想法是显示进度条.其他一切都还可以,但我无法弄清楚如何刷新通知中的进度条.有人知道任何模式吗?我的意思是,我应该在服务或活动中刷新进度条等等.
ColdFusion代码中有什么方法可以确定代码执行的服务器是什么?我有几个负载均衡的ColdFusion服务器.我希望能够知道在捕获异常时代码运行在哪个服务器上,因此我可以在记录/报告代码中包含该信息.
服务器是Windows 2003/IIS,如果这很重要.我也很想知道如何在Linux/Apache中做到这一点.:-)
基本上我使用listviews插入事件插入图像,尝试从fileupload控件调整图像大小,然后使用LINQ将其保存在SQL数据库中.
我找到了一些代码来在fileupload控件中创建内容的新位图,但这是将它存储在服务器上的一个文件中,从这个来源,但我需要将位图保存回SQL数据库,我认为我需要转换回byte []格式.
那么如何将位图转换为byte []格式?
如果我以错误的方式解决这个问题,我将不胜感激,你可以纠正我.
这是我的代码:
// Find the fileUpload control
string filename = uplImage.FileName;
// Create a bitmap in memory of the content of the fileUpload control
Bitmap originalBMP = new Bitmap(uplImage.FileContent);
// Calculate the new image dimensions
int origWidth = originalBMP.Width;
int origHeight = originalBMP.Height;
int sngRatio = origWidth / origHeight;
int newWidth = 100;
int newHeight = sngRatio * newWidth;
// Create a new bitmap which will hold the previous resized bitmap
Bitmap newBMP …
Run Code Online (Sandbox Code Playgroud) 看看这个简单的功能
def prime_factors(n):
for i in range(2,n):
if n % i == 0:
return i, prime_factors(n / i)
return n
Run Code Online (Sandbox Code Playgroud)
这是结果 prime_factors(120)
(2, (2, (2, (3, 5))))
Run Code Online (Sandbox Code Playgroud)
我希望它返回一个扁平元组或列表,而不是嵌套元组.
(2, 2, 2, 3, 5)
Run Code Online (Sandbox Code Playgroud)
有一个简单的方法吗?
用一个例子可以更好地说明这个问题.我将使用Javascript(实际上是Coffeescript的语法),但仅仅因为Javascript只是另一个LISP,对吧?
所以,假设我正在编写一个(显然)执行ajax请求的Web应用程序.我实现了一个函数来处理:
ajaxRequest = (url, params, callback) ->
# implementation goes here
Run Code Online (Sandbox Code Playgroud)
现在,假设我有一个从服务器获取数据的网格.我的代码中的某处我必须做这样的事情:
userGrid.onMustFetch = ->
ajaxRequest '/fetch/users', { surname: 'MacGyver' }, (data) ->
# fill grid with data
Run Code Online (Sandbox Code Playgroud)
究竟是什么问题?如果我想测试onMustFetch的实现,我将无法这样做,因为在onMustFetch中,正在调用依赖项,并且测试环境无法控制依赖项.
为了解决这个问题,我将依赖项注入到我想要测试的函数中.这意味着将onMustFetch更改为:
userGrid.onMustFetch = (ajaxRequest) ->
ajaxRequest '/fetch/users', { surname: 'MacGyver' }, (data) ->
# fill grid with data
Run Code Online (Sandbox Code Playgroud)
现在测试代码可以将ajaxRequest的模拟传递给onMustFetch并成功测试行为.
Wunderbar,对吧?错误!现在我有一个第二个问题,不必权实例绑定的问题ajaxRequest到正确的实例onMustFetch.
在像Java这样的语言中,我可以使用依赖注入框架为我做这个,我的代码看起来像这样:
class UserGrid {
private AjaxService ajaxService;
@Inject
public UserGrid(AjaxService ajaxService) { …
Run Code Online (Sandbox Code Playgroud) 目前我只知道缓存数据的两种方法(我使用PHP,但我认为这同样适用于大多数语言).
还有其他(也许是更好的)缓存方式,还是真的这么简单?
我正在阅读一本ASP.NET书籍,它涉及CSS文件和有关像素的讨论.但我从未从分辨率,布局等角度理解它.例如,以下CSS文件定义意味着什么?
#header
{
padding: 0px;
margin: 0px;
}
Run Code Online (Sandbox Code Playgroud) 我在新窗口中打开后如何将Firebug停靠在浏览器窗口中?使用Mac OS X 10.5上的Firefox 3.0.8和Firebug 1.3,我无法将其停靠在浏览器窗口中.:(
coldfusion ×2
python ×2
algorithm ×1
android ×1
asp.net-3.5 ×1
byte ×1
c# ×1
caching ×1
css ×1
firebug ×1
firefox ×1
graphics ×1
java ×1
javascript ×1
linq ×1
macos ×1
networking ×1
progress-bar ×1
recursion ×1