我有一个循环以表格形式显示月份。
我想以两种不同的格式显示月份:
像这样:
<option value="01">January</option>
<!-- ... -->
<option value="12">December</option>
Run Code Online (Sandbox Code Playgroud)
问题是,我无法显示此内容。
到目前为止,这是我的代码:
echo '<select name="month">';
for ($x=1; $x<=12; $x++)
{
$val=strlen($x);
if($val==1)
{
echo '<option value="'.'0'.$x.'">'.'0'.$x.'</option>';
} else {
echo '<option value="'.$x.'">'.$x.'</option>';
}
}
echo '</select>';
Run Code Online (Sandbox Code Playgroud) 我有以下数据结构:
{
things: [
"desk",
"chair",
"pen",
"book",
"lamp"
],
owners: [
"Julia",
"Sandra",
"John",
"Paul"
]
}
Run Code Online (Sandbox Code Playgroud)
工作原理:
此handleblars模板:
{{#each things}}
<p>This {{this}} belongs to {{lookup ../owners @index}}</p>
{{/each}}
Run Code Online (Sandbox Code Playgroud)
正确输出:
This desk belongs to Julia
This chair belongs to Sandra
This pen belongs to John
This book belongs to Paul
This lamp belongs to
Run Code Online (Sandbox Code Playgroud)
什么不起作用:
现在,我想添加一个条件,因为最后一个thing可能没有owner。模板将如下所示:
{{#each things}}
{{#if lookup ../owners @index}}
<p>This {{this}} belongs to {{lookup ../owners @index}}</p>
{{else}}
<p>...But this {{this}} …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种绘制分布直方图的方法,y-axis代表每个bin的项目总数(而不仅仅是计数).
以下图表中的示例:
它并不像看起来那么微不足道,因为人们不能简单地将每个箱子的数量乘以箱子的价值(可能在20-30箱子中,有54个代理商卖出21个,其中1个卖出29个).
问题:
matplotlib或seaborn?使用async/await?执行在 Python 中并行运行的两个异步循环的好方法是什么?
我也想过类似下面的代码,但不能换我围绕着如何使用头async/ await/EventLoop在这种特殊情况下。
import asyncio
my_list = []
def notify():
length = len(my_list)
print("List has changed!", length)
async def append_task():
while True:
time.sleep(1)
await my_list.append(random.random())
notify()
async def pop_task():
while True:
time.sleep(1.8)
await my_list.pop()
notify()
loop = asyncio.get_event_loop()
loop.create_task(append_task())
loop.create_task(pop_task())
loop.run_forever()
Run Code Online (Sandbox Code Playgroud)
预期输出:
$ python prog.py
List has changed! 1 # after 1sec
List has changed! 0 # after 1.8sec
List has changed! 1 # after 2sec
List has changed! 2 # …Run Code Online (Sandbox Code Playgroud) 有一张像这样的电影表:
genre revenue
array<string> int
---------------------------
[Drama] 10000
[Drama, Fiction] 2000
[Fiction] 300
[Comedy] 5000
[Comedy, Fiction] 500
Run Code Online (Sandbox Code Playgroud)
如何按包含的流派对电影进行分组并进行聚合,例如:
genre count_movies sum_revenue
---------------------------------------
Drama 2 12000
Fiction 3 2800
Comedy 2 5500
Run Code Online (Sandbox Code Playgroud)
我查看了数组函数和运算符的文档,但在那个方向找不到任何东西。
负责此输出的查询可能如下所示:
SELECT
COUNT(*) AS count_movies,
SUM(revenue) AS sum_revenue
FROM movies
GROUP BY ARRAY_EXPLODE(genre) -- this is fake, just to illustrate the point
Run Code Online (Sandbox Code Playgroud) 使用 PostgreSQL 10.10,来自超级用户postgres:
CREATE EXTENSION postgres_fdw;
GRANT USAGE ON FOREIGN DATA WRAPPER postgres_fdw TO my_user;
Run Code Online (Sandbox Code Playgroud)
然后在执行以下操作时my_user:
CREATE SERVER my_server
FOREIGN DATA WRAPPER postgres_fdw
OPTIONS (...);
Run Code Online (Sandbox Code Playgroud)
显示此错误消息:
Query 1 ERROR: ERROR: foreign-data wrapper "postgres_fdw" does not exist
Run Code Online (Sandbox Code Playgroud)
以下是当前活动的外部数据包装器的列表(来自 psql):
postgres=# \dew
List of foreign-data wrappers
Name | Owner | Handler | Validator
--------------+----------+----------------------+------------------------
postgres_fdw | postgres | postgres_fdw_handler | postgres_fdw_validator
(1 row)
Run Code Online (Sandbox Code Playgroud)
为什么即使在被授予之后USAGE,用户my_user仍然无法看到/使用 postgres_fdw 外部数据包装器,就好像后者不存在一样?还需要采取更多步骤吗?
我正在导入Data.Text和Data.List,它们各自的find功能崩溃了。
import Data.Text\nimport Data.List\n\nmy_list = [4, 2, 4, 5, 6, 2, 6]\nfind (\\a -> a == 5) my_list\nRun Code Online (Sandbox Code Playgroud)\n上面的代码会导致以下错误
\n Ambiguous occurrence \xe2\x80\x98find\xe2\x80\x99\n It could refer to\n either \xe2\x80\x98Data.Text.find\xe2\x80\x99, imported from \xe2\x80\x98Data.Text\xe2\x80\x99\n or \xe2\x80\x98Data.List.find\xe2\x80\x99,\n imported from \xe2\x80\x98Data.List\xe2\x80\x99\n (and originally defined in \xe2\x80\x98Data.Foldable\xe2\x80\x99)\nRun Code Online (Sandbox Code Playgroud)\n是这里使用的唯一解决方案Data.List.find (\\a -> a == 5) my_list,还是合格的进口?
让我印象深刻的是
\n Ambiguous occurrence \xe2\x80\x98find\xe2\x80\x99\n It could refer to\n either \xe2\x80\x98Data.Text.find\xe2\x80\x99, imported from \xe2\x80\x98Data.Text\xe2\x80\x99\n or \xe2\x80\x98Data.List.find\xe2\x80\x99,\n imported from \xe2\x80\x98Data.List\xe2\x80\x99\n …Run Code Online (Sandbox Code Playgroud) 我想知道如何IO [Int]在 GHCI 中映射一个。
?: :{
?| th :: IO [Int]
?| th = pure [1, 2, 3, 4]
?| :}
?: th
[1,2,3,4]
?: :t th
th :: IO [Int]
?: map (+2) th
• Couldn't match expected type ‘[b]’ with actual type ‘IO [Int]’
• In the second argument of ‘map’, namely ‘th’
In the expression: map (+ 2) th
Run Code Online (Sandbox Code Playgroud)
想要的结果:
?: res = map (+2) th -- <-- some working version of this
?: res …Run Code Online (Sandbox Code Playgroud) 使用这样的case _ of语法:
fun a b c =
case (a, b, c) of
(Just True, Just _, _) -> foo
(Just True, _, Just _) -> foo
_ -> bar
Run Code Online (Sandbox Code Playgroud)
我可以合并前两个条件并避免重复foo吗?
或者,有没有其他(更干净的)方式来表达我想运行foo当且仅当aisJust True和bor or cnot Nothing?
从 Numpy nd 数组开始:
>>> arr
[
[
[10, 4, 5, 6, 7],
[11, 1, 2, 3, 4],
[11, 5, 6, 7, 8]
],
[
[12, 4, 5, 6, 7],
[12, 1, 2, 3, 4],
[12, 5, 6, 7, 8]
],
[
[15, 4, 5, 6, 7],
[15, 1, 2, 3, 4],
[15, 5, 6, 7, 8]
],
[
[13, 4, 5, 6, 7],
[13, 1, 2, 3, 4],
[14, 5, 6, 7, 8]
],
[
[10, 4, 5, 6, …Run Code Online (Sandbox Code Playgroud) haskell ×3
python ×3
sql ×2
arrays ×1
asynchronous ×1
event-loop ×1
ghci ×1
group-by ×1
histogram ×1
html ×1
io-monad ×1
javascript ×1
matplotlib ×1
module ×1
numpy ×1
php ×1
postgresql ×1
presto ×1
python-3.x ×1
seaborn ×1