当我做:
l = []
for i in range(10):
if i%3 == 0 or i%5 == 0:
l.append[i]
print sum(l)
Run Code Online (Sandbox Code Playgroud)
我明白了
Traceback (most recent call last):
File "PE1.py", line 4, in <module>
l.append[i]
TypeError: 'builtin_function_or_method' object is not subscriptable
Run Code Online (Sandbox Code Playgroud)
真的没有办法追加通过条件的所有i吗?
我正在使用此功能按金额按顺序添加新项目.此功能每30-50ms调用一次.
var insertBefore = false;
container.find('.roll-user-row[data-user-id="' + user_data.id + '"]').remove();
container.children().each(function () {
var betContainer = $(this), itemAmount = $(this).attr('data-amount'), betId = $(this).attr('data-user-id');
if (itemAmount < betData.totalAmount) {
insertBefore = betContainer;
return false;
}
});
if (insertBefore) {
$(template).insertBefore(container);
} else {
container.prepend(template);
}
Run Code Online (Sandbox Code Playgroud)
itemAmount = $(this).attr('data-amount')是整数,betData.totalAmount也是整数.如果附加速度低于±300毫秒 - 一切都运行良好.如果快速追加我得到这个结果:
这甚至没有关闭我想要的 - 那是随机的.怎么解决这个?
我正在使用 kibana 和 Elasticsearch 版本 5.1.1 和 python 版本 3.6。
我已经像这样创建了索引 put_books
添加用户的功能是这样的:
def add_user(first_name, last_name, age, mail):
doc = {"first_name": "" + first_name, "last_name": "" + last_name, "age": age, "email": "" + mail}
global id_user
res = es.index(index="books", doc_type="user", id=id_user, body=doc)
id_user += 1
print(res['result'])
Run Code Online (Sandbox Code Playgroud)
并添加首选项:
def add_preferences(preferences, i):
doc = es.get(index="books", doc_type="user", id=id_book)
res = es.update(index="books", doc_type="user", id=i, body={'doc':{"keyword_preferences": preferences}})
Run Code Online (Sandbox Code Playgroud)
我的问题是:当我想添加首选项时,它会成功,但如果我想再次添加首选项,它会替换它:
id_user = 1
nom = "nom_1"
prenom = "prenom_1"
age = 45
email = "adresse_mail_1" …Run Code Online (Sandbox Code Playgroud) 我有 2 个文件文本:file1.txt
abc
fdg
erg
Run Code Online (Sandbox Code Playgroud)
文件2.txt
pot
ezr
fds
Run Code Online (Sandbox Code Playgroud)
我制作了一个包含 2 列的 csv 文件
columns = ['first','second']
my_df = pd.DataFrame(columns = columns)
Run Code Online (Sandbox Code Playgroud)
我不知道如何在列上添加文件 txt
我想
first second
0 abc pot
1 fdg ezr
2 erg fds
Run Code Online (Sandbox Code Playgroud)
我尝试使用 loc 或追加,但结果很糟糕。我不知道如何将文件文本中的项目放在 df 上的好位置。你能帮助我吗 ?
我有两个数据框想要附加在一起。以下是示例。
df_1:
Code Title
103 general checks
107 limits
421 horseshoe
319 scheduled
501 zonal
Run Code Online (Sandbox Code Playgroud)
df_2
Code Title
103 hello
108 lucky eight
421 little toe
319 scheduled cat
503 new item
Run Code Online (Sandbox Code Playgroud)
仅当 df_2 中的代码号在 df_1 中不存在时,我才想将 df_2 附加到 df_1。
下面是我想要的数据框:
Code Title
103 general checks
107 limits
421 horseshoe
319 scheduled
501 zonal
108 lucky eight
503 new item
Run Code Online (Sandbox Code Playgroud)
我已经通过 Google 和 Stackoverflow 进行了搜索,但找不到有关此特定案例的任何内容。
每当调用模型范围时是否可以将属性附加到我的模型?
例如,在我的控制器中,我想调用一个作用域来附加这些动态属性,例如:
$Media_query = OutDoorMedia::query();
$Media_query->orderby('created_at', 'desc');
$Media_query->PreviouslyOrdered();
$Media = $Media_query->get();
Run Code Online (Sandbox Code Playgroud)
在我的模型中我想做类似的事情:
class OutDoorMedia extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'id',
'user_id',
'address',
'location',
'media_type',
];
}
class scopePreviouslyOrdered extends OutDoorMedia
{
public $appends = ['previously_ordered'];
public function getPreviouslyOrderedAttribute()
{
if ($this->hasMany('App\Models\OutDoorMediaOrders', 'odm_id', 'id')->Where(function ($query) {
$query->where('status', MEDIA_ORDER_CHECKOUT_STATUS)
->orWhere('status', STATUS_TO_PAY);
})->exists()) {
return true;
} else {
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
}
但它不起作用,我知道这是错误的,如何实现这一目标?
我对Kotlin绝对陌生,似乎我无法获取追加文件过程。我有val路径给定的文件名:String =“ ..... txt”我想在我的类中使用以下方法:line:String并将其附加在文件的末尾(在新行上)。我的测试用例是:用两个不同的行对方法进行两次结果调用,例如“ foo”和“ bar”,我希望文件如下:
foo
bar
Run Code Online (Sandbox Code Playgroud)
如果我的方法如下所示,它将起作用:
fun writeLine(line: String) {
val f = File(path!!)
f.appendText(line + System.getProperty("line.separator"))
}
Run Code Online (Sandbox Code Playgroud)
而且它绝对不会以这种方式工作:
fun writeLine(line: String) {
val f = File(path!!)
f.bufferedWriter().use { out->
out.append(line)
out.newLine()
}
}
Run Code Online (Sandbox Code Playgroud)
每次调用时都会重写我的文件,因此我的文件中只有“ bar”。它也不能与printWriter一起使用:
fun writeLine(line: String) {
val f = File(path!!)
f.printWriter().use { out->
out.append(line)
}
}
Run Code Online (Sandbox Code Playgroud)
我得到的结果与BufferedWriter相同。为什么?我就是听不懂。如何附加BufferedWriter或PrintWriter?
我有这个 for 循环,它调用产生数字向量的函数
例如,向量将导致:
[1] 42 42 6 693 6222
Run Code Online (Sandbox Code Playgroud)
从上面的 for 循环。
我想将“x”添加到每个向量的开头。看来去的效率不高
append("x", vec1)
# This is an example of what I want produced:
[1] x 42 42 6 693 6222
Run Code Online (Sandbox Code Playgroud)
多次。有没有办法将“x”添加为 for 循环内的第一个元素?谢谢。
代码如下:
<p-table
[columns]="colsHistoryLogEntryList"
[value]="entity.historyLogEntryList"
[resizableColumns]="true"
[autoLayout]="true"
[paginator]="true"
[rows]="5"
[rowsPerPageOptions]="[5, 10, 25, 50, 100]"
paginatorDropdownAppendTo="body"
class="ui-table-historyEntry-list"
[rowHover]="true"
>
Run Code Online (Sandbox Code Playgroud)
当页面最大化时,下拉列表呈现到底部并且部分隐藏。但是当页面缩小时,它会正确地呈现为向上方向。
如何强制下拉列表始终可见?

我有带有分组变量“ID”和一些值的数据:
ID, Value
1, 1
1, 2
1, 3
1, 4
2, 5
2, 6
2, 7
2, 8
Run Code Online (Sandbox Code Playgroud)
在每个组中,我想在最后一行之后附加第一行。期望的结果:
ID, Value
1, 1
1, 2
1, 3
1, 4
1, 1 # First row of ID 1 inserted as last row in the group
2, 5
2, 6
2, 7
2, 8
2, 5 # First row of ID 2 inserted as last row in the group
Run Code Online (Sandbox Code Playgroud)
我有 5000 行这个。