python


How to find specific list among other lists


I am a beginner in python and have a question.
I am using python 3.6.0
How do I find the name of a list which contains specific items, among other lists?
C1 = ['X', 'O', '1', '1']
C2 = ['X', 'O', '2', '1']
C3 = ['X', 'O', '3', '1']
C4 = ['X', 'O', '4', '1']
C5 = ['X', 'O', '5', '1']
C6 = ['X', 'O', '1', '2']
C7 = ['X', 'O', '2', '2']
C8 = ['X', 'O', '3', '2']
C9 = ['X', 'O', '4', '2']
C10 = ['X', 'O', '5', '2']
C11 = ['X', 'O', '1', '3']
C12 = ['X', 'O', '2', '3']
C13 = ['X', 'O', '3', '3']
C14 = ['X', 'O', '4', '3']
C15 = ['X', 'O', '5', '3']
C16 = ['X', 'O', '1', '4']
C17 = ['X', 'O', '2', '4']
C18 = ['X', 'O', '3', '4']
C19 = ['X', 'O', '4', '4']
C20 = ['X', 'O', '5', '4']
C21 = ['X', 'O', '1', '5']
C22 = ['X', 'O', '2', '5']
C23 = ['X', 'O', '3', '5']
C24 = ['X', 'O', '4', '5']
C25 = ['X', 'O', '5', '5']
Let's say I wanted to find the name of the list which has 5 in the third position and 2 in the 4 position. How and what do I code to get the name of the list?
Find the name of the list which has 5 in the third position and 2 in the 4 position. How and what do I code to get the name of the list?
You can check the content in each list name to see if that list contains the desired condition.
However, I assume you don't want to type "C1", "C2" all the way to "C25". So here you can use the keyword: "eval".
This way you don't have to concatenate your small lists into a big list.
Sample Usage:
>>> x = 1
>>> print eval('x+1')
2
for i in range(1, 26):
ListName = "C"+str(i)
if eval(ListName)[2] == "5" and eval(ListName)[3] == "2":
print(ListName, "is the list you are looking for!")
Put these lists in a list, and iterate over them using a loop.
for listItem in bigList:
if listItem[2] == '5' and listItem[3] == '2'
# do something with the listItem
# this is the list satisfying the condition you wanted
Do you mean this ?
cList = []
c9 = ['X', 'O', '5', '2']
c10 = ['X', 'O', '5', '2']
# .....
cList.append(c9)
cList.append(c10)
for cItem in cList:
if '5' == cItem[2] and '2' == cItem[3]:
print("YES!")

Related Links

execute api function on button click using Django urls - Django/Python
Get indices of N maximum values in a numpy array, with random tie-breaking
Improve String Comparison Time For Numpy Array
Parsing JSON-RPC using Python
Numpy with Blas and OpenBlas take the same time
How can I make a transfer function for an RC circuit in python
Using SL4a to make intent that adds new contact
Text file not being imported with module
Web.py - prevent caching of code/output
Reference counting while adding element to list
Python: Trouble with dill installation
python open file error
Dealing with Sprites and Collisions Using Pygame
Pip-installed module does not import
Does a trailing comma after an n-tuple in Python change its value?
Program that either waits for user input or runs at defined intervals?

Categories

HOME
visual-studio-2015
caching
symfony
ssas-2012
filterrific
sed
avro
deep-linking
actionscript
ruby-on-rails-3
ll
ios10
value
bro
apiconnect
websphere-liberty
eval
cartodb
cockroachdb
ndis
symfony-forms
titan
redux-observable
google-openid
attask
multicore
cython
cocoa-touch
jquery-scrollify
nmf
cronet
tfs2013
metis
mayavi
autofill
roundcube
twitter-bootstrap-2
graph-databases
google-drive-realtime-api
node-horseman
bigcartel
s3cmd
sendgrid-templates
productivity
pdftk
ivona
python-idle
azureportal
opencpu
sqldatareader
iostat
scalar
nofollow
metalsmith
dojox.charting
date-format
selecteditem
mpeg-4
eml
asp.net-mvc-2
galaxy
data-import
datasnap
abas
digits
bridge
isml
virus
searchkick
word-2013
jai
jcr-sql2
client-side-validation
c++-actor-framework
inputaccessoryview
java-melody
log4cplus
sthttprequest
method-overriding
coin-flipping
operations
gamepad
modeshape
iconv
mvs
attachevent
git-filter-branch
gdt
parameterization
applicationcontext
text-services-framework
entity-framework-ctp5
electronic-signature
executable-format
rijndael
out-of-browser
recordset
hibernate3-maven-plugin
clients
grooveshark
plinq
microsoft.ink
outlook-form

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App