我有一个python列表,其中包含1000个.就像是:
data=["I","am","a","python","programmer".....]
Run Code Online (Sandbox Code Playgroud)
其中,len(数据)=说1003
我现在想通过将原始列表拆分为100个块来创建此列表(数据)的子集.所以,最后,Id喜欢有类似的东西:
data_chunk1=[.....] #first 100 items of list data
data_chunk2=[.....] #second 100 items of list data
.
.
.
data_chunk11=[.....] # remainder of the entries,& its len <=100, len(data_chunk_11)=3
Run Code Online (Sandbox Code Playgroud)
是否有一种pythonic方式来完成这项任务?显然我可以使用数据[0:100]等等,但我认为这非常非pythonic且非常低效.
非常感谢.
说我有两个简单的清单,
a = ['Spears', "Adele", "NDubz", "Nicole", "Cristina"]
b = [1,2,3,4,5]
len(a) == len(b)
Run Code Online (Sandbox Code Playgroud)
我想做的是随机化a,b但维持秩序.所以,像:
a = ["Adele", 'Spears', "Nicole", "Cristina", "NDubz"]
b = [2,1,4,5,3]
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用以下方式对一个列表进行洗牌:
import random
random.shuffle(a)
Run Code Online (Sandbox Code Playgroud)
但这只是随机化a,而我想随机化a,并保持列表中的"随机顺序" b.
希望得到关于如何实现这一目标的任何指导.
我是python和正则表达式(regex newbie here)的新手,我有以下简单的字符串:
s=r"""99-my-name-is-John-Smith-6376827-%^-1-2-767980716"""
Run Code Online (Sandbox Code Playgroud)
我想只提取上面字符串中的最后一位数字,即767980716,我想知道如何使用python正则表达式实现这一点.
我想做类似的事情:
re.compile(r"""-(.*?)""").search(str(s)).group(1)
Run Code Online (Sandbox Code Playgroud)
表示我想找到介于两者之间的东西(.*?),以" - "开头并以字符串结尾结束 - 但这不会返回任何内容.
我想知道是否有人能指出我正确的方向..谢谢.
我在64位Ubuntu上遇到了一个奇怪的问题 - 在export命令上.
基本上,我在Win7上的Ubuntu上安装了VM,我正在尝试使用自定义(由客户端提供)软件将命令从我的窗口传递到我的VM安装.
所以,在我的VM上,当我这样做时:
export foo=bar
echo $foo
Run Code Online (Sandbox Code Playgroud)
一切都按预期工作.
但是,当我通过自定义软件(基本上将linux命令作为字符串传递给bash shell)时,我得到:
export: command not found
Run Code Online (Sandbox Code Playgroud)
我尝试使用以下方法查看shell(使用自定义软件):
echo $SHELL>shell.txt
Run Code Online (Sandbox Code Playgroud)
我得到/ bin/bash这是预期的,我仍然得到导出:命令未找到错误.
我想知道以前是否有人见过这个错误?
我对git很陌生,在过去的两个月里我一直在做一个小型项目,并且没有任何问题就把东西推到了bitbucket上.几天前,我压缩了我的项目文件夹(因为我不得不重新安装我的Linux操作系统),现在在重新安装Linux操作系统后将其解压缩.
所以,现在,我去了我的项目文件夹,保持愉快的工作,最后做了:
git add -A && git commit -m "modified code" && git push origin master
Run Code Online (Sandbox Code Playgroud)
..这是我通常做的..
我得到:
To https://johnsproject@bitbucket.org/johnsproject/proj.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://johnsproject@bitbucket.org/johnsproject/proj.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Run Code Online (Sandbox Code Playgroud)
我已经看过几个SO问题,他们建议使用强制标志-f- 但我不确定我是否应该这样做.
ps:我在主分支 - …
我一直在尝试用C扩展python,到目前为止,基于文档,我在编写小型C函数和使用Python扩展它方面取得了相当大的成功.
但是,我现在遇到了一个相当简单的问题 - 我无法找到解决方案.所以,我想做的是传递double list给我的C函数.例如,要传递int,我执行以下操作:
int squared(int n)
{
if (n > 0)
return n*n;
else
return 0;
}
static PyObject*
squaredfunc(PyObject* self, PyObject* args)
{
int n;
if (!PyArg_ParseTuple(args, "i", &n))
return NULL;
return Py_BuildValue("i", squared(n));
}
Run Code Online (Sandbox Code Playgroud)
这将int n没有任何问题传递给我的C函数命名squared.
但是,如何将一个传递list给C函数?我确实尝试谷歌并阅读文档,到目前为止,我还没有找到任何有用的东西.
如果有人能指出我正确的方向,我真的很感激.
谢谢.
我有一个 MP4 文件,我希望将其转换为 WAV 文件,其中包含签名的 16 位 PCM 样本。我有 ffmpeg 可供使用,并且查看了以前的 SOF 帖子,我尝试过:
ffmpeg -y -i input.mp4 -acodec pcm_s16le -f s16le -ac 1 -ar 16000 output.pcm
Run Code Online (Sandbox Code Playgroud)
但是,我使用的程序抱怨这个转换后的文件包含未知格式的数据。我想知道是否有人有关于如何使用 pcm 样本从 m4a 到 wav 的任何指示。
我有一个使用Django 1.4构建的小博客应用程序,最近,我一直在学习html5和css3的"点点滴滴".我是关于开始将我的网站转换为html5/css3,我想知道Django小部件是否支持html5(?)
我的博客没什么特别的 - 一些表格,几张表等等.例如,当我这样做时,
{{form_as_p}}
Run Code Online (Sandbox Code Playgroud)
我想知道django是否会生成所需的html5标记(?)我阅读了文档,它说管理页面支持html5,但我找不到常规应用程序的任何文档.
如果Django不支持html5,那么实现这一目标的最佳方法是什么?
谢谢你的时间.
在尝试根据元素字符串长度对数组进行排序时,我遇到了编译错误.我有一套开始,
Set<String> arraycat = new HashSet<String>();
//add contents to arraycat
String[] array = arraycat.toArray(new String[0]);
//array looks like this now:
//array=[cat,cataaaa,cataa,cata,cataaa]
Run Code Online (Sandbox Code Playgroud)
我理想的是要排序到
array=[cat,cata,cataa,cataaa,cataaaa]
Run Code Online (Sandbox Code Playgroud)
所以我有一个类型的比较器
class comp implements Comparator {
public int compare(String o1, String o2) {
if (o1.length() > o2.length()) {
return 1;
} else if (o1.length() < o2.length()) {
return -1;
} else {
return 0;
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后我打电话给上课
Collections.sort(array, new comp());
Run Code Online (Sandbox Code Playgroud)
但是,它抛出了两个编译错误:
comp is not abstract and does not override abstract method compare(java.lang.Object,java.lang.Object) in java.util.Comparator
class comp …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用django-haystack(现在大约2天),我已经有了基本的入门示例工作,它看起来非常令人印象深刻.我现在想在haystack上尝试自动完成功能.
http://readthedocs.org/docs/django-haystack/en/v1.2.4/autocomplete.html
第一部分似乎很好:"设置数据"似乎很简单.但是,我不确定需要在哪里写"执行查询":即我应该在哪个视图中包含:
from haystack.query import SearchQuerySet
sqs = SearchQuerySet().filter(content_auto=request.GET.get('q', ''))
Run Code Online (Sandbox Code Playgroud)
我目前的urls.py很简单,设置如下:
urlpatterns = patterns('',
# Examples:
('^hello/$', hello),
(r'^$', hello),
(r'^search/', include('haystack.urls')),
# url(r'^$', 'mysite.views.home', name='home'),
# url(r'^mysite/', include('mysite.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
#url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)
Run Code Online (Sandbox Code Playgroud)
看下面的博客:
http://tech.agilitynerd.com/haystack-search-result-ordering-and-pre-rende
我希望有类似的东西:
url(r'^search/', SearchView(load_all=False,searchqueryset=sqs),name='haystack_search'),
Run Code Online (Sandbox Code Playgroud)
但是,应该在哪里指定sqs?在urls.py或views.py?我试过两个,但他们给我一个名称错误"请求"在sqs语句中找不到.
python ×4
django ×2
audio ×1
bitbucket ×1
c ×1
ffmpeg ×1
git ×1
git-commit ×1
java ×1
linux ×1
pcm ×1
python-2.7 ×1
python-c-api ×1
regex ×1
ubuntu ×1