我想在Python中实现HashMap.我想问一个用户输入.根据他的输入,我正在从HashMap中检索一些信息.如果用户输入HashMap的键,我想检索相应的值.
如何在Python中实现此功能?
HashMap<String,String> streetno=new HashMap<String,String>();
streetno.put("1", "Sachin Tendulkar");
streetno.put("2", "Dravid");
streetno.put("3","Sehwag");
streetno.put("4","Laxman");
streetno.put("5","Kohli")
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Flex 和 Bison 为简单的格式化语言构建一个编译器。我还处于起步阶段,我已经编写了一些功能。
不过,在这个阶段,我仍然没有将yyout任何东西打印到任何地方。我有一些错误情况,其中输出文件中打印了某些内容,但此输入显然不会发生这种情况。我所有的其他打印语句都将打印到控制台。因此,我希望输出文件将完全为空。但是,当我尝试使用以下内容作为我的输入文件时:
\begin {document}
\tabsize( 5)
\title{"Why I Love Compiler Design"}
\author{"COMP421 Student"}
\date{29/12/2016}
\pagesetup{30,100 }
\end{document}
Run Code Online (Sandbox Code Playgroud)
生成的输出文件为:
有 9 行空行,对应于我在输入文件中的 9 行。然而,我期望的输出只有 1 个空行。
这是我的.l文件:
\begin {document}
\tabsize( 5)
\title{"Why I Love Compiler Design"}
\author{"COMP421 Student"}
\date{29/12/2016}
\pagesetup{30,100 }
\end{document}
Run Code Online (Sandbox Code Playgroud)
这是我的.y文件:
%{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "y.tab.h"
void yyerror(const char *);
int yylex(void);
/* "Connect" with the output file */
extern FILE *yyout;
extern int yyparse(); …Run Code Online (Sandbox Code Playgroud) 我试图在Python中减去字母,但我不能以正确的方式做到这一点.
我知道如何得到ord这封信.
喜欢:
a = "a"
x = ord(a) # -> this will give me 97.
Run Code Online (Sandbox Code Playgroud)
当我尝试从该字母中减去值时,得到的结果与我想要的完全不同.
如果我减去1从b我得到的97(代表a),但现在我想减去14从b,我想达到a,然后回去z,继续减法.
a = 97
b = 98
...
z = 122
Run Code Online (Sandbox Code Playgroud)
我想继续循环使用小写字母,它位于97和之间122.
例如,如果我减去14从b,我得到的84,但我想这样做,我想获得的方式n.
b - 14 = a - 13 = z - 12 (...) and so on.
Run Code Online (Sandbox Code Playgroud)
我希望你能理解我的意思.
;)
有人能帮我一下吗 ?
此致,伊万.