由买买提看人间百态

topics

全部话题 - 话题: dict
1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
r****t
发帖数: 10904
1
http://blog.labix.org/2008/06/27/watch-out-for-listdictkeys-in-python-3
Watch out for list(dict.keys()) in Python 3
Gustavo Niemeyer
As everyone is probably aware by now, in Python 3 dict.keys(), dict.values()
and dict.items() will all return iterable views instead of lists. The
standard way being suggested to overcome the difference, when the original
behavior was actually intended, is to simply use list(dict.keys()). This
should be usually fine, but not in all cases.
One of the reasons why som
O*****y
发帖数: 222
2
用 python 写的。在网上找到的,自己改了一点。
原来用过一个用到 w3m 的 shell script,速度比这个慢。
用法:
dict word
or
dict group of words (e.g. "dict make of")
d********t
发帖数: 9628
3
在dict套dict的情况下。
k*****u
发帖数: 1688
4
输入的data是这样的:
user1 user2 user3
book1 1 3 5
book2 3 1
book3 2 4
book4 3 1 5
book5 1 2 4
希望得到的数据是这样的:
{user1: {book1:1, book2:3, book3:2, book4:3, book5:1}, user2:{book1:3, book3
:4, book4:1, book5:2}, user3:{book1:5, book2:1, book4:5, book5:4}}
谢谢
另外,一般用python的话,平时数据都是什么格式的?好像dict的最多。习惯了array
格式的的data,一下子到python这儿变成dict有些不习惯。
x*****g
发帖数: 151
5
界面很简单,但是内容却是非常的丰富,自信没有别的词典网站有我的这没多的内容。
http://www.stormcolin.com/dict
x*****g
发帖数: 151
6
界面很简单,但是内容却是非常的丰富,自信没有别的词典网站有我的这么多的内容。
http://www.stormcolin.com/dict
wh
发帖数: 141625
7
【 以下文字转载自 Translation 讨论区 】
发信人: wh (wh), 信区: Translation
标 题: dict.cn翻译的"need-blind admission"
发信站: BBS 未名空间站 (Tue Sep 23 22:47:34 2014, 美东)
“需要盲目招生” :DDD
wh
发帖数: 141625
8
【 以下文字转载自 Translation 讨论区 】
发信人: wh (wh), 信区: Translation
标 题: dict.cn翻译的"need-blind admission"
发信站: BBS 未名空间站 (Tue Sep 23 22:47:34 2014, 美东)
“需要盲目招生” :DDD
x*****g
发帖数: 151
9
界面很简单,但是内容却是非常的丰富,自信没有别的词典网站有我的这个多的内容。
http://www.stormcolin.com/dict
G********d
发帖数: 10250
10
来自主题: PhotoGear版 - urban dict真是好用
刚才跳跳和谁谁推荐jcrew和gap
然后我就查了下urban dict 看看这些牌子和穿这些牌子的人的stereotype
结果很快查到关键词
preppy...for jcrew
labor dispute for GAP...
很欢乐
s*****e
发帖数: 21415
11
来自主题: PhotoGear版 - urban dict真是好用
urban dict还有这功能?
m**********n
发帖数: 84
12
来自主题: Apple版 - 写了一个小app draw dict
帮你猜draw something的答案 功能极其简单 学习ios的产物 呵呵 free 大家有空不妨
下来玩玩 顺便提提意见 谢谢大家!
http://itunes.apple.com/us/app/draw-dict/id514838149?mt=8
v****s
发帖数: 1112
13
【 以下文字转载自 JobHunting 讨论区 】
发信人: vicfcs (ML+CV), 信区: JobHunting
标 题: dict.cn 的词库是crawl到的吗?
发信站: BBS 未名空间站 (Sat Dec 18 16:51:26 2010, 美东)
连例句和翻译都有。。。而且没有版权问题?
O*****y
发帖数: 222
14
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import httplib
from xml.dom import minidom
from textwrap import wrap
class PyDict:
def __init__(self):
self.server = 'dict.cn'
self.port = 80
self.url = '/ws.php'
self.method = 'POST'
self.header = {'Content-Type':'application/x-www-form-urlencoded', '
User-Agent':'PyDict'}
def query(self, word):
word = str(word) # be sure a string
if len(word.strip()) == 0:
print
i**i
发帖数: 1500
15
dict1 && dict1[key] && dict[key][key2] || {};
d********t
发帖数: 9628
16
来自主题: Programming版 - python有快速loop over dict的方法吗?
其实是有三层的dict要全部print出来,似乎一层层loop太慢。
s*****V
发帖数: 21731
17
先放到LIST
users = [u1,u2,u3]
lines = [[book1,1,2,3],....]
cols = zip(*lines)
data = {}
for i,user in enumerate(users):
data.update({user:dict(zip(cols[0],cols[i+1]))})

book3
m********2
发帖数: 89
18
"pandas" or "sqlite" should be used for single PC tabular data processing.
Don't
abuse dict.

book3
t****a
发帖数: 1212
19
来自主题: JobHunting版 - 问一道题(10)
可以用DP来做。计算复杂度大约为n^3*len(dict)
假设输入字符串s长度为n,f为求解的函数,那么
f(s, dict) = match_dict(s, dict) 当s可以直接匹配上dict里的某字符串(通过排序
后比较), match_dict返回dict中匹配上的字符串
f(s, dict) = (max the words length) [f(subs(s, 0, i), dict), f(subs(s, i, n)
, dict)], i=1..n-1 当s不能直接找到dict里的匹配
f(s, dict) = nil 当s为空
clojure程序如下
(defn gen-sorted-dict [dict]
(reduce merge (for [w dict]
{(sort w) w})))
(defn match-dict [s sorted-dict]
(sorted-dict (sort s)))
(def prob10-sub
(memoize
(fn [s sorted-dict]
(wh... 阅读全帖
y****e
发帖数: 23939
20
来自主题: Programming版 - Visual C++ 高手帮忙,一个Link Error
I paste the full code to if anybody can help me out.
the function refalifn and refalifnfast are good to compile on vc++.
But the function refalidf and refalifdf will have this LNK2019 error on vc++
. Same code compiles OK on g++. It must be some kind of restraint with
visual c++.
static double refalifn(const gsl_vector * v, void *params)
{
Dict *dict = (Dict *) params;
double x = gsl_vector_get(v, 0);
double y = gsl_vector_get(v, 1);
double a = gsl_vector_get(v, 2);
EMData *t... 阅读全帖
i******s
发帖数: 301
21
来自主题: JobHunting版 - 问两道google题
你的解法应该是对的,基于这个写了如下C++代码
/*
* Author: Shengzhe Yao
* Date: 08 Nov 2010
*/
#include
#include
#include
#include
using namespace std;
// T(n) = \sum_{i=1}^{n-1} (T(i) * H(i+1))
int findAllStr(const set &dict, char *str,
int end, int *lookup_table) {
if (lookup_table[end] > 0)
return lookup_table[end];
int total = 0;
for (int i=1; i < end; ++i) {
char *substr = (str+i+1);

if (dict.find(substr) != dict.end()) {
char tmp =... 阅读全帖
J**9
发帖数: 835
22
来自主题: JobHunting版 - wordbreak in C?
Problem at
http://discuss.leetcode.com/questions/765/word-break
This does not seem to be a DP problem, just do it in a straightforward way.
Here's my implementation in C. Any issue?
Thanks.
//===========================================================
#include
#include
#include
#include
#include
/**
* Given a string s and a dictionary of words dict, determine if s can be
segmented into a space-separated sequence of one or more
* dictionary w... 阅读全帖
V*****i
发帖数: 92
23
来自主题: JobHunting版 - 问两道google题
There is no need to pass Dictionary and lookup table, use global variable or
use class. My solution as follows:
#include
#include
#include
#include
using namespace std;
// T(n) = \sum_{i=1}^{n-1} (T(i) * H(i+1))
const int MAXSIZE = 100;
class find_str {
private:
set dict;
int lookup_table[MAXSIZE];
public:
find_str(set &d) {
dict = d;
for (int i=0; i ... 阅读全帖
x*******5
发帖数: 152
24
来自主题: JobHunting版 - google电面杯具,贡献题目
凑热闹,给个runable的code
/*Descriptoin: given a dictionary of words, find the longest word in the
dictionary such that it can be built from successively adding a single
character to an existing word in the dictionary in any location
Input: Dict& dict, vector v, vector & result
Output: void
K.O.: back tracking
*/
vector String::generate_next_string(string& s, String::Dict& dict){
string t;
vector v;
set temp;
for(int i=0;i<26;i++){
... 阅读全帖
p*****2
发帖数: 21240
25
我写了一下,用的greedy的算法。没想到反例,但是感觉也不容易证明。
from heapq import *
class Node:
def __init__(self, val):
self.val=val
self.In=set()
self.Out=set()
def __cmp__(self, other):
if len(self.Out) return 1
elif len(self.Out)>len(other.Out):
return -1
else:
return 0
def __str__(self):
return self.val+":"+str(self.In)+":"+str(self.Out)

courses=[['D','A'],['D','B'],['E','B'],['F','A'],['F','C'],... 阅读全帖
l******s
发帖数: 3045
26
来自主题: JobHunting版 - LinkedIn onsite一道题
Tested on Coderpad. Looks good.
private static ISet getPal(string s){
IDictionary> dict = new Dictionary>();
for(int i = 0; i < s.Length; i++){
if(!dict.ContainsKey(s[i])) dict[s[i]] = new List();
dict[s[i]].Add(i);
}
ISet result = new HashSet();
dfs(result, new StringBuilder(), new StringBuilder(), s, 0, s.Length - 1,
dict);
return result;
}
private static void dfs(ISet result, StringBuilder sLeft,
String... 阅读全帖
l******s
发帖数: 3045
27
来自主题: JobHunting版 - LinkedIn onsite一道题
Tested on Coderpad. Looks good.
private static ISet getPal(string s){
IDictionary> dict = new Dictionary>();
for(int i = 0; i < s.Length; i++){
if(!dict.ContainsKey(s[i])) dict[s[i]] = new List();
dict[s[i]].Add(i);
}
ISet result = new HashSet();
dfs(result, new StringBuilder(), new StringBuilder(), s, 0, s.Length - 1,
dict);
return result;
}
private static void dfs(ISet result, StringBuilder sLeft,
String... 阅读全帖
l********1
发帖数: 24
28
来自主题: JobHunting版 - rocket fuel第一轮面经
void dfs(int n1, int n2, int n3, string transfer, set &dict){
if(n1 == 0 && n2 == 0 && n3 == 0){
if(dict.find(transfer) == dict.end()){
dict.insert(transfer);
cout< }
return;
}
if(transfer.size() == 0){
if(n1 > 0){
string temp = "()";
dfs(n1 - 1, n2, n3, temp, dict);
}
if(n2 > 0){
string temp = "[]" ;
dfs(n1, n2 - 1, n3, temp, dict); ... 阅读全帖
A*H
发帖数: 127
29
来自主题: JobHunting版 - 问两道google题
#q2
#include
#include
using namespace std;
int partition_count(map dict, string words) {
int count = 0;
if (dict[words])
count++;

for (int i=1, n=words.size(); i if (dict[words.substr(0, i)])
count += partition_count(dict, words.substr(i, n-i));
}
return count;
}
int main() {
map dict;
dict["aaa"] = true;
dict["bb"] = true;
dict["cc"] = true;
dict["aaabb"] = true;
dict["bbcc"] = true;
string words = ... 阅读全帖
D********g
发帖数: 650
30
来自主题: JobHunting版 - 一道G家店面题
加上了backtracking:
static class DPElement {
int value;
int prevCostIdx; // 0-based cost idx
int takenThisElement; // 0/1, indicating whether taking current
element, idx 0 based.
public DPElement() {
value = 0;
prevCostIdx = 0;
takenThisElement = 0;
}
}
static String word2Anagram(final String word) {
if (word == null) {
return null;
}

int ht[] = new int[256];
f... 阅读全帖
t*****h
发帖数: 137
31
来自主题: JobHunting版 - 话说今天面了一老印
#include
#include
#include
using namespace std;
bool find_begin_word(string &sentence, vector &dict, vector &
space_pos, int pos)
{
int new_pos = 0;
bool found = false;
for ( int i = 0; i < dict.size() && !found; ++i )
{
int w_len = dict[i].length();
if ( pos + w_len <= sentence.length() && sentence.substr(pos, w_len) ==
dict[i] )
{
new_pos = pos + w_len;
if ( new_pos == sentence.length() )
{
space_pos.push_... 阅读全帖
t*****h
发帖数: 137
32
来自主题: JobHunting版 - 话说今天面了一老印
#include
#include
#include
using namespace std;
bool find_begin_word(string &sentence, vector &dict, vector &
space_pos, int pos)
{
int new_pos = 0;
bool found = false;
for ( int i = 0; i < dict.size() && !found; ++i )
{
int w_len = dict[i].length();
if ( pos + w_len <= sentence.length() && sentence.substr(pos, w_len) ==
dict[i] )
{
new_pos = pos + w_len;
if ( new_pos == sentence.length() )
{
space_pos.push_... 阅读全帖
c*****a
发帖数: 808
33
import java.util.Hashtable;
public class Solution {
Hashtable Dict = new Hashtable ()
;
public ArrayList letterCombinations(String digits) {
ArrayList res = new ArrayList();
if(digits.length()==0){
res.add("");
return res;
}
Dict.put(2, new String[]{"a", "b", "c"});
Dict.put(3, new String[]{"d", "e", "f"});
Dict.put(4, new String[]{"g", "h", "i"});
... 阅读全帖
d*****y
发帖数: 1365
34
来自主题: JobHunting版 - 10分钟前的F家电二面面经(必挂)
int numofword(string& S)
{
unordered_set dict;
dict.insert(string("a"));
dict.insert(string("an"));
dict.insert(string("em"));
dict.insert(string("fir"));
dict.insert(string("fire"));
dict.insert(string("ire"));
dict.insert(string("ma"));
dict.insert(string("man"));
vector vNumW(S.size()+1,-1);
... 阅读全帖
n*******w
发帖数: 687
35
来自主题: JobHunting版 - 问一个word ladder的题目
recrusion试过,5个字母的单词都算不出来。假设字典50w单词,长度为5的单词只有几
千个。
这题我这么算的
1 先从字典里边选出长度为要找的单词的所有单词
2 建立dict,key是单词本身,value是从start到这个单词的路径长度,初始值为
integer的最大值,假设是MAX。
3 dict[start] = 0; dict[end] = MAX
4 对于dict里边每一个单词cur_word,
如果dict[cur_word] != MAX, 改变cur_word的任一个字符得到next_word,看next_
word是不是在dict里边,如果存在则更新dict[next_word] =
min( dict[next_word], 1+ dict[cur_word] )
5 如果step 4没有任何改变,退出。输出dict[end]
实际上DP,也可以看做是,建图并且Dijkstra一起做。
python写的话,不超过20行。运行时间在半分钟之内。
t********f
发帖数: 1964
36
来自主题: Apple版 - 妈蛋ios 9不能用h2o的数据了
把下面的内容复制到记事本,并把扩展名改成.mobileconfig,例如:H2OWireless.
mobileconfig,用email发到邮箱里,在手机上打开安装就能解决了.

http://www.apple.com/DTDs/PropertyList-1.0.dtd">


ConsentText

default
APN

PayloadContent


AttachAPN

Name
att.mvno
AuthenticationType
CHAP阅读全帖
D********g
发帖数: 650
37
来自主题: JobHunting版 - 一道G家店面题
20分钟写了大约下面的code,如果要输出string,还要backtrack:
static String word2Anagram(final String word) {
if (word == null) {
return null;
}

int ht[] = new int[256];
for (int i = 0; i < word.length(); ++i) {
int charVal = (int) word.charAt(i);
ht[charVal] ++;
}

StringBuilder anagram = new StringBuilder();
for (int i = 0; i < ht.length; ++i) {
if (ht[i] > 0) {
anagram.append((cha... 阅读全帖
n**********e
发帖数: 45
38
来自主题: JobHunting版 - Groupon 2面 面经
感觉预处理字典挺麻烦的,如果字典很大呢?
试贴一简单解法:
bool check(unordered_set& dict, char *a, int i) {
// a[] is a permutation of the char set
// based on the elements a[0]-a[i], check if a[] a could be a solution.
int N = 4, k= (i+1)/N; // k: complete line number
string s(a,a+N*N);
for (int l = 0; l if ( dict.find(s.substr(l*N,N)) == dict.end() ) return false;
if (k==N-1) { // check columns
for(int n= 0; n < (i+1)%N; n++) {
string t("");
... 阅读全帖
n**********e
发帖数: 45
39
来自主题: JobHunting版 - Groupon 2面 面经
感觉预处理字典挺麻烦的,如果字典很大呢?
试贴一简单解法:
bool check(unordered_set& dict, char *a, int i) {
// a[] is a permutation of the char set
// based on the elements a[0]-a[i], check if a[] a could be a solution.
int N = 4, k= (i+1)/N; // k: complete line number
string s(a,a+N*N);
for (int l = 0; l if ( dict.find(s.substr(l*N,N)) == dict.end() ) return false;
if (k==N-1) { // check columns
for(int n= 0; n < (i+1)%N; n++) {
string t("");
... 阅读全帖
y*****i
发帖数: 141
40
来自主题: JobHunting版 - 问道G家的题
照着Maxthon的编码解法写了一个:
#include
#include
#include
#include
using namespace std;
bool bool_vec_none(const vector & vec) {
for(auto elem : vec) {
if (elem) {
return false;
}
}
return true;
}
bool bool_vec_all(const vector & vec) {
for(auto elem : vec) {
if (!elem) {
return false;
}
}
return true;
}
string word_abbreviation(string target, vector dict)
{
if (t... 阅读全帖
d****n
发帖数: 397
41
我一开始也没过。但是注意到不是所有parent都要记录。BFS里面同级之间的parent不
要记录,就可以了。
这是我写的python 解法。
#! /usr/bin/python
import collections
class Solution:
# @param start, a string
# @param end, a string
# @param dict, a set of string
# @return a list of lists of string
def findLadders(self, start, end, dict):
alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n',
'o','p','q','r','s','t','u','v','w','x','y','z']
dict = dict | set([end])
dict = dict | set([start])
... 阅读全帖
m**********g
发帖数: 153
42
来自主题: JobHunting版 - leetcode word break II DFS 超时
先dp, 然后dfs, 用dp信息剪枝.
class Solution {
void getSentence(string &s, int start, string sentence, vector &
output, unordered_set &dict, bool *breakable)
{
if(start == s.size()) {
sentence.erase(sentence.end() -1);
output.push_back(sentence);
return;
}
for(int i=start; i if(breakable[i+1] == false) //prune here
continue;
string tmp=s.substr(start, i-start+1);
... 阅读全帖
d******4
发帖数: 132
43
来自主题: JobHunting版 - Course Schedule II DFS版
欢迎各位大牛批评指导。统计背景,正在刷题,希望得到cs专家的指导。
class Solution:
# @param {integer} numCourses
# @param {integer[][]} prerequisites
# @return {integer[]}
def findOrder(self, numCourses, prerequisites):
if not prerequisites:
return range(numCourses)
dict={}
for e in prerequisites:
if e[0] not in dict:
dict[e[0]] = [e[1]]
else:
if e[1] not in dict[e[0]]:
dict[e[0]].append(e[1])
... 阅读全帖
D********g
发帖数: 650
44
来自主题: JobHunting版 - google电面杯具,贡献题目
第二题,我的code,主要算法是recursion + memoization,有没有人能分析一下这个
算法的复杂度?
static String findLongestDecomposableWord(Set dict) {
String longest = null;
Set mem = new HashSet();
for (String word : dict) {
if (findLongestDecomposableWordInternal(word, mem, dict)) {
if (longest == null || word.length() > longest.length()) {
longest = word;
}
}
}

return longest;
}
... 阅读全帖
S******t
发帖数: 151
45
来自主题: JobHunting版 - onsite后收到A家的拒信,面经。
我大概写一个吧,没编译,不知道靠谱不
#include
#include
#include
using namespace std;
string dict[MAXNUM];
vector graph[MAXNUM];
bool visited[MAXNUM];
bool diff_one(string a,string b) {
int len_a = (int)a.size();
int len_b = (int)b.size();
if (len_a != len_b) return false;
int cnt = 0;
for(int i=0;i if(a[i]!=b[i]) cnt++;
return cnt == 1;
}
void preprocess() {
int dict_sz = (int)dict.size();
for(int i=0;i for(int j=i+1;j ... 阅读全帖
S******t
发帖数: 151
46
来自主题: JobHunting版 - onsite后收到A家的拒信,面经。
我大概写一个吧,没编译,不知道靠谱不
#include
#include
#include
using namespace std;
string dict[MAXNUM];
vector graph[MAXNUM];
bool visited[MAXNUM];
bool diff_one(string a,string b) {
int len_a = (int)a.size();
int len_b = (int)b.size();
if (len_a != len_b) return false;
int cnt = 0;
for(int i=0;i if(a[i]!=b[i]) cnt++;
return cnt == 1;
}
void preprocess() {
int dict_sz = (int)dict.size();
for(int i=0;i for(int j=i+1;j ... 阅读全帖
j*****y
发帖数: 1071
47
来自主题: JobHunting版 - 10分钟前的F家电二面面经(必挂)
想了一下,一维数组确实够了 :)
int numberSpaceNeed(string s, unordered_set & dict)
{
int n = s.length();
int dp[n];
if(dict.find(s.substr(0, 1)) != dict.end())
{
dp[0] = 0;
}
else
{
dp[0] = n;
}
for(int i = 1; i < n; ++i)
{
if(dict.find(s.substr(0, i + 1)) != dict.end())
{
dp[i] = 0;
}
else
... 阅读全帖
r*****e
发帖数: 146
48
来自主题: JobHunting版 - 大家G电面都是几轮?(附题目)
agree,if the people in the past thousand of years are too many, we can
simplify it by recording the visited ancestor.
// for the root id, dict[root_id] == "#";
// dict is something like map
bool share_ancestor(map dict, string c1, string c2){
set found;
while(true){
if(check(c1,dict, found))
return true;
if(check(c2,dict, found))
return true;
if(c1 == "#" && c2 == "#")
return false;
... 阅读全帖
1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)