我刚开始玩Python(VBA背景).为什么这本字典无序创建?不应该是:1,b:2 ......等等?
class Card:
def county(self):
c = 0
l = 0
groupL = {} # groupL for Loop
for n in range(0,13):
c += 1
l = chr(n+97)
groupL.setdefault(l,c)
return groupL
pick_card = Card()
group = pick_card.county()
print group
Run Code Online (Sandbox Code Playgroud)
这是输出:
{'a': 1, 'c': 3, 'b': 2, 'e': 5, 'd': 4, 'g': 7, 'f': 6, 'i': 9, 'h': 8, 'k': 11, 'j': 10, 'm': 13, 'l': 12}
Run Code Online (Sandbox Code Playgroud)
或者,它是否只是打印失序?
我正在尝试学习python(我的VBA背景)购买黑杰克游戏作为教学练习.
我做了一些关于传递多个参数的搜索,但我真的不明白我在解释的方式中找到了什么.
查看最后一个名为'hand'的函数,我试图利用三个单独的值作为前一个函数的'return'传递.
我收到以下错误:
Traceback (most recent call last):
File "decky15.py", line 56, in <module>
print hand(deal(shuffle(load_deck())))
TypeError: hand() takes exactly 3 arguments (1 given)
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?我怎样才能更有效率?对解决方案或读数的任何建议都非常感谢.
import random
def load_deck():
suite = ('Spades', 'Hearts', 'Diamonds', 'Clubs')
rank = ('2', '3', '4', '5', '6', '7', '8', '9', '10', "Jack", "Queen", "King", "Ace")
full_deck = {}
i = 0
for s in suite:
for r in rank:
full_deck[i] = "%s of %s" % (r, s)
i += 1
return full_deck
def pick_item(dict_in_question): …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的mac上学习mongo db.我使用自制软件安装了mondgo db,它成功了.我创建了dir /data/db.当我输入mongo终端时,我得到:
Error: couldn't connect to server [a bunch of numbers] at src/mongo/shell/mongo.js:145 exception:connect failed
Run Code Online (Sandbox Code Playgroud)
我在SO上查看了以下答案: 在OSX上安装和运行MongoDB
在检查答案中说:1)为您的mongo服务器启动终端2)转到mongo/bin目录
为您的服务器启动终端是什么意思?这是否意味着只是打开一个新的终端窗口?
我在哪里可以找到mongo/bin目录?
关于让mondoDB启动并运行的任何其他建议将不胜感激.
我mongod在我的mac终端上输入并收到以下错误:
2015-04-27T22:11:46.471-0400 W - [initandlisten] Detected unclean shutdown - /data/db/mongod.lock is not empty.
2015-04-27T22:11:46.479-0400 I STORAGE [initandlisten] **************
old lock file: /data/db/mongod.lock. probably means unclean shutdown,
but there are no journal files to recover.
this is likely human error or filesystem corruption.
please make sure that your journal directory is mounted.
found 4 dbs.
see: http://dochub.mongodb.org/core/repair for more information
Run Code Online (Sandbox Code Playgroud)
如何确保我的日志目录已挂载?那能解决问题吗?
我一直收到以下错误:
解析错误:语法错误,第70行/home/a4999406/public_html/willingLog.html中的意外T_SL
在以下代码上(第一行是第70行):
echo <<<END
<form action = "willingLog.html" method="post"><pre>
First <input type="text" name="first" />
Last <input type="text" name="last" />
Email <input type="text" name="email" />
Username <input type="text" name="user_name" />
<input type="submit" value="AD RECORD" />
</pre></form>
END;
Run Code Online (Sandbox Code Playgroud)
heredoc似乎没有用.我试过其他的例子.
以下是doctype标题.那里有什么不对吗?
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
Run Code Online (Sandbox Code Playgroud) 我正在寻找一个简单的例子和/或解释如何使用error参数.ajax.
这个问题(jQuery ajax错误函数)指向这个我不明白的jQuery文档(http://api.jquery.com/jQuery.ajax/).
我有以下代码不起作用,我无法弄清楚为什么.我希望error参数会有所帮助:
jQuery的:
<script>
// wait for the DOM to be loaded
$(document).ready(function() {
// bind 'myForm' and provide a simple callback function
$("#myForm").submit(function(){
var user_input = $("#signup_id_email").val();
$.ajax
({
type: "POST",
url: "ajax_test.php",
dataType: 'json',
data: {email: user_input},
**error: ""**
})
.done(function(r)
{
$("#answer_id").append(r.email);
});
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
PHP(ajax_text.php)
<?php
echo json_encode($_POST);
?>
Run Code Online (Sandbox Code Playgroud) 现在我正在使用以下代码将股票代码列表从小写字母转换为大写字母:
Dim Tickers As String
Dim n As Integer
For n = 2 To Last
Tickers = UCase(W.Cells(n, 1).Value)
W.Cells(n, 1).Value = Tickers
Next n
Run Code Online (Sandbox Code Playgroud)
有没有一种方法可以用来将整个范围转换成一行?就像是:
Range("A1:A20").convertouppercasesomehow
Run Code Online (Sandbox Code Playgroud) 如果我有一个dict列表,如:
{
'id1': ['a', 'b', 'c'],
'id2': ['a', 'b'],
# etc.
}
Run Code Online (Sandbox Code Playgroud)
我想计算清单的大小,即.id的数量> 0,> 1,> 2 ......等
有没有比嵌套for循环更简单的方法:
dictOfOutputs = {}
for x in range(1,11):
count = 0
for agentId in userIdDict:
if len(userIdDict[agentId]) > x:
count += 1
dictOfOutputs[x] = count
return dictOfOutputs
Run Code Online (Sandbox Code Playgroud) 我知道关于这个主题已经写了很多。然而,我无法吸收其中的大部分。也许是因为我是一个完整的新手,没有任何计算机科学培训的好处。无论如何,也许如果你们中的一些大智慧在这个特定的例子中加入,你会帮助像我这样的其他初学者。
所以,我编写了以下函数,当我调用它(作为模块?)时,它工作得很好,因为它是自己的名为“funky.py”的文件:
我在终端中输入以下内容:
python classy.py
Run Code Online (Sandbox Code Playgroud)
它运行良好。
def load_deck():
suite = ('Spades', 'Hearts')
rank = ('2', '3')
full_deck = {}
i = 0
for s in suite:
for r in rank:
full_deck[i] = "%s of %s" % (r, s)
i += 1
return full_deck
print load_deck()
Run Code Online (Sandbox Code Playgroud)
但是,当我在类中放置相同的函数时,出现错误。
这是我的“classy.py”代码:
class GAME():
def load_deck():
suite = ('Spades', 'Hearts')
rank = ('2', '3')
full_deck = {}
i = 0
for s in suite:
for r in rank:
full_deck[i] = "%s of %s" % (r, …Run Code Online (Sandbox Code Playgroud) 我正在尝试从书中学习python("Hello!Python").根据这本书,这段代码应该发送一封电子邮件.到目前为止没有运气.
import os
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib
def send_message(message):
s = smtplib.SMTP('smtp.me.com')
s.sendmail(message['From'], message['To'], message.as_string())
s.quit()
def mail_report(to, ticker_name):
outer = MIMEMultipart()
outer['Subject'] = "Stock report for " + ticker_name
outer['From'] = "myemail@mac.com"
outer['To'] = to
# Internal text container
inner = MIMEMultipart('alternative')
text = "Here is the stock report for " + ticker_name
html = """\
<html>
<head></head>
<body>
<p>Here is teh stock report for
<b> """ + ticker_name + """ </b>
</p> …Run Code Online (Sandbox Code Playgroud)