为[string] / [list in list]中的值赋值

时间:2016-01-11 23:33:42

标签: python arrays list python-3.x

我正在创建一个纸牌游戏 - 二十一点 - 并且需要向用户显示一个字符串,但要跟踪每张卡值得进行计算的点数。所以,我创建了一个包含卡片所有值的列表:

cards = [1,1,1,1,2,2,2,2,3,3,3,3,...]

但是对于用户来说,例如,如果列表中的项目是King,我想显示13。我如何制作包含这些值的字典/键或数组?我不能使用基于位置的字典,因为一旦发卡,我会将其从list / deck中删除。

3 个答案:

答案 0 :(得分:3)

您只需定义字符串列表:

cardnames = ["Ace","2","3","4","5","6","7","8","9","10","Jack","Queen","King"]

现在,如果该卡的值为v,则可以使用cardnames[v-1]获取相应的名称。例如:

v = 5
print("I have a %s"%cardnames[v-1])

在这种情况下,对于Queen 12和King 13,jack的值为11。例如(使用python的交互式shell):

$ python
Python 2.7.9 (default, Apr  2 2015, 15:33:21) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> cardnames = ["Ace","2","3","4","5","6","7","8","9","10","Jack","Queen","King"]
>>> v=12
>>> print("I have a %s"%cardnames[v-1])
I have a Queen
>>> v=7
>>> print("I have a %s"%cardnames[v-1])
I have a 7
>>> v=1
>>> print("I have a %s"%cardnames[v-1])
I have a Ace
>>> v=13
>>> print("I have a %s"%cardnames[v-1])
I have a King

或使用python3

$ python3
Python 3.4.3 (default, Mar 26 2015, 22:03:40) 
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> cardnames = ["Ace","2","3","4","5","6","7","8","9","10","Jack","Queen","King"]
>>> v=12
>>> print("I have a %s"%cardnames[v-1])
I have a Queen
>>> v=7
>>> print("I have a %s"%cardnames[v-1])
I have a 7
>>> v=1
>>> print("I have a %s"%cardnames[v-1])
I have a Ace
>>> v=13
>>> print("I have a %s"%cardnames[v-1])
I have a King

答案 1 :(得分:1)

在内部,您可以将卡片表示为其值。 Aces为1,国王为13等......

你可以构建你的" deck"正如你所期待的那样。一个[1,1,1,1,2,2,2,...]的列表,并操纵你想要的。

要实际向用户显示卡片,请使用Willem提到的卡片名单。这将起作用,因为卡片值1将对应于卡片名单列表的第一个(第0个)位置中的卡片名称:" Ace"。

例如:

Python 3.4.1 |Anaconda 2.1.0 (64-bit)| (default, Sep 10 2014, 17:10:18) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> cardnames = ["Ace","2","3","4","5","6","7","8","9","10","Jack","Queen","King"]
>>> hand = [1,1,2,4,6,3,11,8]
>>> for x in hand:
...  print(cardnames[x-1])
... 
Ace
Ace
2
4
6
3
Jack
8

答案 2 :(得分:1)

您可以使用字典进行从号码到卡片名称的翻译。像这样:

2016-01-12 12:38:35,801 INFO  [org.hibernate.Version] (ServerService Thread Pool -- 60) HHH000412: Hibernate Core {4.3.11.Final}
2016-01-12 12:38:35,834 INFO  [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 60) HHH000206: hibernate.properties not found
2016-01-12 12:38:35,838 INFO  [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 60) HHH000021: Bytecode provider name : javassist
2016-01-12 12:38:36,222 INFO  [org.hibernate.annotations.common.Version] (ServerService Thread Pool -- 60) HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
2016-01-12 12:38:36,642 INFO  [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 60) HHH000400: Using dialect: org.hibernate.dialect.SQLServer2008Dialect
2016-01-12 12:38:36,763 INFO  [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (ServerService Thread Pool -- 60) HHH000397: Using ASTQueryTranslatorFactory
2016-01-12 12:38:37,296 INFO  [org.hibernate.type.BasicTypeRegistry] (ServerService Thread Pool -- 60) HHH000270: Type registration [java.util.Currency] overrides previous : org.hibernate.type.CurrencyType@5e4d3f75
2016-01-12 12:38:37,500 WARN  [org.jboss.weld.Event] (MSC service thread 1-3) WELD-000411: Observer method [BackedAnnotatedMethod] protected org.apache.deltaspike.core.impl.exclude.extension.ExcludeExtension.vetoBeans(@Observes ProcessAnnotatedType<Object>, BeanManager) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
2016-01-12 12:38:37,519 WARN  [org.jboss.weld.Event] (MSC service thread 1-3) WELD-000411: Observer method [BackedAnnotatedMethod] protected org.apache.deltaspike.core.impl.message.MessageBundleExtension.detectInterfaces(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
2016-01-12 12:38:37,562 WARN  [org.jboss.weld.Event] (MSC service thread 1-3) WELD-000411: Observer method [BackedAnnotatedMethod] public org.omnifaces.VetoAnnotatedTypeExtension.processAnnotatedType(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
2016-01-12 12:38:37,683 INFO  [org.apache.deltaspike.core.util.ClassDeactivationUtils] (MSC service thread 1-3) class: org.apache.deltaspike.core.impl.jmx.MBeanExtension activated=true
2016-01-12 12:38:37,689 INFO  [org.apache.deltaspike.core.util.ClassDeactivationUtils] (MSC service thread 1-3) class: org.apache.deltaspike.core.impl.message.MessageBundleExtension activated=true
2016-01-12 12:38:37,692 INFO  [org.apache.deltaspike.core.util.ClassDeactivationUtils] (MSC service thread 1-3) class: org.apache.deltaspike.core.impl.config.ConfigurationExtension activated=true
2016-01-12 12:38:37,693 INFO  [org.apache.deltaspike.core.util.ClassDeactivationUtils] (MSC service thread 1-3) class: org.apache.deltaspike.core.impl.exception.control.extension.ExceptionControlExtension activated=true
2016-01-12 12:38:37,737 INFO  [org.apache.deltaspike.core.util.ClassDeactivationUtils] (MSC service thread 1-3) class: org.apache.deltaspike.core.impl.exclude.extension.ExcludeExtension activated=true
2016-01-12 12:38:37,737 INFO  [org.apache.deltaspike.core.util.ClassDeactivationUtils] (MSC service thread 1-3) class: org.apache.deltaspike.core.impl.exclude.CustomProjectStageBeanFilter activated=true
2016-01-12 12:38:37,737 INFO  [org.apache.deltaspike.core.util.ClassDeactivationUtils] (MSC service thread 1-3) class: org.apache.deltaspike.core.impl.exclude.GlobalAlternative activated=true
2016-01-12 12:38:38,379 INFO  [org.jboss.weld.Bootstrap] (weld-worker-5) WELD-000119: Not generating any bean definitions from org.apache.deltaspike.cdise.weld.WeldContainerControl because of underlying class loading error: Type org.jboss.weld.environment.se.Weld from [Module "deployment.pos-war-1.0-SNAPSHOT.war:main" from Service Module Loader] not found.  If this is unexpected, enable DEBUG logging to see the full error.
2016-01-12 12:38:39,046 INFO  [stdout] (abcdCacheManager) 2016-01-12 12:38:39,025 [abcdCacheManager] INFO net.sf.ehcache.util.UpdateChecker - New update(s) found: 2.4.7 [http://www.terracotta.org/confluence/display/release/Release+Notes+Ehcache+Core+2.4]. Please check http://ehcache.org for the latest version.

2016-01-12 12:38:39,065 INFO  [org.apache.deltaspike.core.util.ProjectStageProducer] (MSC service thread 1-3) Computed the following DeltaSpike ProjectStage: Production
2016-01-12 12:38:42,380 WARN  [org.jboss.weld.Validator] (MSC service thread 1-3) WELD-001471: Interceptor method init defined on class com.abcd.xyz.web.jsf.HomeScreenImageHandlingBean is not defined according to the specification. It should not throw com.abcd.xyz.api.exception.FileValidationException, which is a checked exception.
2016-01-12 12:38:42,395 WARN  [org.jboss.weld.Validator] (MSC service thread 1-3) WELD-001471: Interceptor method init defined on class com.abcd.xyz.web.jsf.BrandingResourcesHandlingBean is not defined according to the specification. It should not throw com.abcd.xyz.api.exception.FileValidationException, which is a checked exception.
2016-01-12 12:38:43,026 INFO  [stdout] (MSC service thread 1-8) 2016-01-12 12:38:43 JRebel: Directory 'D:\Repo\pos\source\pos-web\target\classes' will be monitored for changes.

2016-01-12 12:38:43,213 INFO  [stdout] (MSC service thread 1-8) 2016-01-12 12:38:43,212 [MSC service thread 1-8] WARN com.abcd.xyz.database.DatabaseUpdateManager - Call flyway database upgrade... 

2016-01-12 12:38:43,278 INFO  [org.flywaydb.core.internal.dbsupport.DbSupportFactory] (MSC service thread 1-8) Database: jdbc:sqlserver://localhost:1433;authenticationScheme=nativeAuthentication;xopenStates=false;sendTimeAsDatetime=true;trustServerCertificate=false;sendStringParametersAsUnicode=true;selectMethod=direct;responseBuffering=adaptive;packetSize=8000;multiSubnetFailover=false;loginTimeout=15;lockTimeout=-1;lastUpdateCount=true;encrypt=false;disableStatementPooling=true;databaseName=pos;applicationName=Microsoft JDBC Driver for SQL Server;applicationIntent=readwrite; (Microsoft SQL Server 12.0)
2016-01-12 12:38:43,675 INFO  [org.flywaydb.core.internal.command.DbMigrate] (MSC service thread 1-8) Current version of schema [dbo]: 2.7.0.004
2016-01-12 12:38:43,677 INFO  [org.flywaydb.core.internal.command.DbMigrate] (MSC service thread 1-8) Schema [dbo] is up to date. No migration necessary.
2016-01-12 12:38:43,812 INFO  [stdout] (MSC service thread 1-8) 2016-01-12 12:38:43,812 [MSC service thread 1-8] WARN com.abcd.xyz.database.DatabaseUpdateManager - Database migration finished... 

2016-01-12 12:38:43,833 INFO  [stdout] (MSC service thread 1-8) 2016-01-12 12:38:43,833 [MSC service thread 1-8] INFO com.abcd.xyz.web.servletListeners.PluginListener - Plugin initialisation listener started.

2016-01-12 12:38:44,204 ERROR [org.jboss.as.ejb3.invocation] (MSC service thread 1-8) JBAS014134: EJB Invocation failed on component PluginManager for method public void com.abcd.xyz.managers.PluginManager.updateAllPluginInfos(): javax.ejb.EJBException: java.lang.IllegalArgumentException: Not an entity: class com.abcd.xyz.domain.entity.plugin.PluginInfo
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:190) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:275) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:340) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:239) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.ejb3.component.invocationmetrics.WaitTimeInterceptor.processInvocation(WaitTimeInterceptor.java:43) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.ejb3.security.SecurityContextInterceptor.processInvocation(SecurityContextInterceptor.java:95) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.ejb3.component.interceptors.ShutDownInterceptorFactory$1.processInvocation(ShutDownInterceptorFactory.java:64) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:55) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.invocation.ContextClassLoaderInterceptor.processInvocation(ContextClassLoaderInterceptor.java:64)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:326)
    at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:448)
    at org.jboss.invocation.AccessCheckingInterceptor.processInvocation(AccessCheckingInterceptor.java:61)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:326)
    at org.jboss.invocation.PrivilegedWithCombinerInterceptor.processInvocation(PrivilegedWithCombinerInterceptor.java:80)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
    at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:185)
    at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:182)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
    at org.jboss.as.ee.component.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:73)
    at com.abcd.xyz.managers.PluginManager$$$view10.updateAllPluginInfos(Unknown Source) [:]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_66]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_66]
    at sun.reflect.DelegatingMethodAccessorImpl.__invoke(DelegatingMethodAccessorImpl.java:43) [jrebel-bootstrap-07cc5ac1ac8578423af5afeac7e47c71.jar:1.8.0_66]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java) [jrebel-bootstrap-07cc5ac1ac8578423af5afeac7e47c71.jar:1.8.0_66]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java) [jrebel-bootstrap-07cc5ac1ac8578423af5afeac7e47c71.jar:1.8.0_66]
    at java.lang.reflect.Method.invoke(Method.java:497) [jrebel-bootstrap-07cc5ac1ac8578423af5afeac7e47c71.jar:1.8.0_66]
    at org.jboss.weld.util.reflection.Reflections.invokeAndUnwrap(Reflections.java:414) [weld-core-impl-2.2.6.Final.jar:2014-10-03 10:05]
    at org.jboss.weld.bean.proxy.EnterpriseBeanProxyMethodHandler.invoke(EnterpriseBeanProxyMethodHandler.java:127) [weld-core-impl-2.2.6.Final.jar:2014-10-03 10:05]
    at org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:56) [weld-core-impl-2.2.6.Final.jar:2014-10-03 10:05]
    at org.jboss.weld.bean.proxy.InjectionPointPropagatingEnterpriseTargetBeanInstance.invoke(InjectionPointPropagatingEnterpriseTargetBeanInstance.java:65) [weld-core-impl-2.2.6.Final.jar:2014-10-03 10:05]
    at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:100) [weld-core-impl-2.2.6.Final.jar:2014-10-03 10:05]
    at com.abcd.xyz.managers.PluginManager$Proxy$_$$_Weld$EnterpriseProxy$.updateAllPluginInfos(Unknown Source) [:]
    at com.abcd.xyz.web.servletListeners.PluginListener.contextInitialized(PluginListener.java:46) [:]
    at io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:173) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:193) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:87)
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.start(UndertowDeploymentService.java:72)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [jrebel-bootstrap-07cc5ac1ac8578423af5afeac7e47c71.jar:1.8.0_66]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [jrebel-bootstrap-07cc5ac1ac8578423af5afeac7e47c71.jar:1.8.0_66]
    at java.lang.Thread.run(Thread.java:745) [jrebel-bootstrap-07cc5ac1ac8578423af5afeac7e47c71.jar:1.8.0_66]
Caused by: java.lang.IllegalArgumentException: Not an entity: class com.abcd.xyz.domain.entity.plugin.PluginInfo
    at org.hibernate.jpa.internal.metamodel.MetamodelImpl.entity(MetamodelImpl.java:203) [hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
    at org.hibernate.jpa.criteria.QueryStructure.from(QueryStructure.java:139) [hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
    at org.hibernate.jpa.criteria.CriteriaQueryImpl.from(CriteriaQueryImpl.java:173) [hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
    at com.abcd.xyz.repository.GenericRepository.findAll(GenericRepository.java:152) [:]
    at com.abcd.xyz.managers.PluginManager.updateAllPluginInfos(PluginManager.java:54) [:]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_66]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_66]
    at sun.reflect.DelegatingMethodAccessorImpl.__invoke(DelegatingMethodAccessorImpl.java:43) [jrebel-bootstrap-07cc5ac1ac8578423af5afeac7e47c71.jar:1.8.0_66]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java) [jrebel-bootstrap-07cc5ac1ac8578423af5afeac7e47c71.jar:1.8.0_66]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java) [jrebel-bootstrap-07cc5ac1ac8578423af5afeac7e47c71.jar:1.8.0_66]
    at java.lang.reflect.Method.invoke(Method.java:497) [jrebel-bootstrap-07cc5ac1ac8578423af5afeac7e47c71.jar:1.8.0_66]
    at org.jboss.as.ee.component.ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptor.java:52)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)
    at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:407)
    at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.doMethodInterception(Jsr299BindingsInterceptor.java:82) [wildfly-weld-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:93) [wildfly-weld-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)
    at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.ejb3.component.invocationmetrics.ExecutionTimeInterceptor.processInvocation(ExecutionTimeInterceptor.java:43) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47) [wildfly-jpa-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:407)
    at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:46) [weld-core-impl-2.2.6.Final.jar:2014-10-03 10:05]
    at org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor.processInvocation(EjbRequestScopeActivationInterceptor.java:83) [wildfly-weld-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.ee.concurrent.ConcurrentContextInterceptor.processInvocation(ConcurrentContextInterceptor.java:45) [wildfly-ee-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
    at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:53)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.ejb3.component.interceptors.NonPooledEJBComponentInstanceAssociatingInterceptor.processInvocation(NonPooledEJBComponentInstanceAssociatingInterceptor.java:59) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:273) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    ... 55 more

2016-01-12 12:38:44,304 INFO  [stdout] (MSC service thread 1-8) 2016-01-12 12:38:44,303 [MSC service thread 1-8] ERROR com.abcd.xyz.web.servletListeners.PluginListener - Lookup and update plugins failed.

2016-01-12 12:38:44,304 INFO  [stdout] (MSC service thread 1-8) javax.ejb.EJBException: java.lang.IllegalArgumentException: Not an entity: class com.abcd.xyz.domain.entity.plugin.PluginInfo

2016-01-12 12:38:44,304 INFO  [stdout] (MSC service thread 1-8)     at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:190) ~[wildfly-ejb3-8.2.0.Final.jar!/:8.2.0.Final]

2016-01-12 12:38:44,339 INFO  [stdout] (MSC service thread 1-8)     at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:275) ~[wildfly-ejb3-8.2.0.Final.jar!/:8.2.0.Final]

2016-01-12 12:38:44,339 INFO  [stdout] (MSC service thread 1-8)     at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:340) ~[wildfly-ejb3-8.2.0.Final.jar!/:8.2.0.Final]

2016-01-12 12:38:44,339 INFO  [stdout] (MSC service thread 1-8)     at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:239) ~[wildfly-ejb3-8.2.0.Final.jar!/:8.2.0.Final]

2016-01-12 12:38:44,339 INFO  [stdout] (MSC service thread 1-8)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) ~[na:na]

2016-01-12 12:38:44,340 INFO  [stdout] (MSC service thread 1-8)     at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41) ~[wildfly-ejb3-8.2.0.Final.jar!/:8.2.0.Final]

2016-01-12 12:38:44,340 INFO  [stdout] (MSC service thread 1-8)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) ~[na:na]

2016-01-12 12:38:44,340 INFO  [stdout] (MSC service thread 1-8)     at org.jboss.as.ejb3.component.invocationmetrics.WaitTimeInterceptor.processInvocation(WaitTimeInterceptor.java:43) ~[wildfly-ejb3-8.2.0.Final.jar!/:8.2.0.Final]

2016-01-12 12:38:44,340 INFO  [stdout] (MSC service thread 1-8)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) ~[na:na]

2016-01-12 12:38:44,340 INFO  [stdout] (MSC service thread 1-8)     at org.jboss.as.ejb3.security.SecurityContextInterceptor.processInvocation(SecurityContextInterceptor.java:95) ~[wildfly-ejb3-8.2.0.Final.jar!/:8.2.0.Final]

2016-01-12 12:38:44,340 INFO  [stdout] (MSC service thread 1-8)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) ~[na:na]

2016-01-12 12:38:44,340 INFO  [stdout] (MSC service thread 1-8)     at org.jboss.as.ejb3.component.interceptors.ShutDownInterceptorFactory$1.processInvocation(ShutDownInterceptorFactory.java:64) ~[wildfly-ejb3-8.2.0.Final.jar!/:8.2.0.Final]

2016-01-12 12:38:44,341 INFO  [stdout] (MSC service thread 1-8)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) ~[na:na]

2016-01-12 12:38:44,341 INFO  [stdout] (MSC service thread 1-8)     at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59) ~[wildfly-ejb3-8.2.0.Final.jar!/:8.2.0.Final]

2016-01-12 12:38:44,341 INFO  [stdout] (MSC service thread 1-8)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) ~[na:na]

2016-01-12 12:38:44,341 INFO  [stdout] (MSC service thread 1-8)     at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50) ~[na:na]

2016-01-12 12:38:44,341 INFO  [stdout] (MSC service thread 1-8)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) ~[na:na]

2016-01-12 12:38:44,341 INFO  [stdout] (MSC service thread 1-8)     at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:55) ~[wildfly-ejb3-8.2.0.Final.jar!/:8.2.0.Final]

2016-01-12 12:38:44,341 INFO  [stdout] (MSC service thread 1-8)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) ~[na:na]

2016-01-12 12:38:44,341 INFO  [stdout] (MSC service thread 1-8)     at org.jboss.invocation.ContextClassLoaderInterceptor.processInvocation(ContextClassLoaderInterceptor.java:64) ~[na:na]

2016-01-12 12:38:44,342 INFO  [stdout] (MSC service thread 1-8)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) ~[na:na]

2016-01-12 12:38:44,342 INFO  [stdout] (MSC service thread 1-8)     at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:326) ~[na:na]

2016-01-12 12:38:44,342 INFO  [stdout] (MSC service thread 1-8)     at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:448) ~[na:na]

2016-01-12 12:38:44,342 INFO  [stdout] (MSC service thread 1-8)     at org.jboss.invocation.AccessCheckingInterceptor.processInvocation(AccessCheckingInterceptor.java:61) ~[na:na]

2016-01-12 12:38:44,342 INFO  [stdout] (MSC service thread 1-8)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) ~[na:na]

2016-01-12 12:38:44,391 INFO  [stdout] (MSC service thread 1-8)     at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:326) ~[na:na]

2016-01-12 12:38:44,391 INFO  [stdout] (MSC service thread 1-8)     at org.jboss.invocation.PrivilegedWithCombinerInterceptor.processInvocation(PrivilegedWithCombinerInterceptor.java:80) ~[na:na]

2016-01-12 12:38:44,391 INFO  [stdout] (MSC service thread 1-8)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) ~[na:na]

2016-01-12 12:38:44,391 INFO  [stdout] (MSC service thread 1-8)     at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) ~[na:na]

2016-01-12 12:38:44,391 INFO  [stdout] (MSC service thread 1-8)     at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:185) ~[na:na]

2016-01-12 12:38:44,392 INFO  [stdout] (MSC service thread 1-8)     at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:182) ~[na:na]

2016-01-12 12:38:44,392 INFO  [stdout] (MSC service thread 1-8)     at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) ~[na:na]

2016-01-12 12:38:44,392 INFO  [stdout] (MSC service thread 1-8)     at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) ~[na:na]

2016-01-12 12:38:44,392 INFO  [stdout] (MSC service thread 1-8)     at org.jboss.as.ee.component.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:73) ~[na:na]

然后,您可以相应地打电话给他们。像:

faces = {
    1: 'Ace',
    2: '2',
    3: '3',
    ...
    11: 'Jack',
    12: 'Queen',
    13: 'King'
}

等于“国王”

详细说明,因为评论中有疑问:

dict(面对的是)是一组键值对。在这种情况下,“密钥”是卡的数值,“值”是卡的面(字符串)。您可以通过它的键来引用dict中的值。

例如。如果我有一个像上面那样的词典,我说:

faces[cardnames[13]]

这就是'Ace'。例如:

faces[1]