hi All,
i have a list and putting an object say "traffic light" in it.
nrTrafficLight=2
objectsList=[]
objectsList.append('TrafficLight')
objTypeList=[]
for i in range(nrTrafficLight):
tl=TrafficLight(id="Taffic Light%s" )
objectsList.append(objTypeList)
i want to use dictionary instead of list here. what will be my code for dictionary.
6 8417
Hi, and welcome! Dictionary lesson to follow.
Please use "start a discussion" button to get your question posted where people will see it (not "reply"). Thanks,
Moderator
hi All,
i have a list and putting an object say "traffic light" in it.
nrTrafficLight=2
objectsList=[]
objectsList.append('TrafficLight')
objTypeList=[]
for i in range(nrTrafficLight):
tl=TrafficLight(id="Taffic Light%s" )
objectsList.append(objTypeList)
i want to use dictionary instead of list here. what will be my code for dictionary.
If I'm reading this correctly (it's hard to tell with such a small chunk of code), "Taffic Light%s" is a string that changes inside the loop.? and you want an object to hold that string.? -
class TrifficLight:
-
def __init__(self, name):
-
self.name = name
-
-
objDict={}
-
name = "Traffic Light 1"
-
tl = TrafficLight(name)
-
objDict[name] = tl
-
Hi all..
I am using lists in my programs now. I wan to use dictionaries instead of lists. Here is a simple code which i have to convert.... its very urgent
Thnx
nrTrafficLight=2
objectsList=[]
objectsList.append('TrafficLight')
objTypeList=[]
for i in range(nrTrafficLight):
tl=TrafficLight(id="Taffic Light%s" )
objectsList.append(objTypeList)
See your previous post "list to dict" a couple of threads down.
plz........
can some one tell me how to convert lists data intio dic,...
bye
bvdet 2,851
Expert Mod 2GB
I do not understand your code, but I made something up that creates a dictionary: - def TrafficLight(id):
-
if id == 'Traffic Light1':
-
return "Green"
-
elif id == 'Traffic Light2':
-
return "Yellow"
-
else:
-
return "Red"
-
-
nrTrafficLight=3
-
-
objectsDict = {}
-
-
for i in range(nrTrafficLight):
-
id = "Traffic Light%s" % (i+1)
-
tl=TrafficLight(id)
-
objectsDict[id] = tl
-
- print objectsDict
-
{'Traffic Light3': 'Red', 'Traffic Light2': 'Yellow', 'Traffic Light1': 'Green'}
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Gabriel B. |
last post by:
I just sent an email asking for hints on how to import data into a
python program
As i said earlier i'm really new to python and besides being
confortable with the syntax, i'm not sure if i'm on...
|
by: flyaflya |
last post by:
a = "(1,2,3)"
I want convert a to tuple:(1,2,3),but tuple(a) return ('(', '1', ',',
'2', ',', '3', ')') not (1,2,3)
|
by: Jan Danielsson |
last post by:
Hello all,
I have written a simple whiteboard application. In my application, I
want to be able to set draw attributes. This part works. I have a
dictionary object which contains stuff like:...
|
by: py |
last post by:
I have two lists which I want to use to create a dictionary. List x
would be the keys, and list y is the values.
x =
y =
Any suggestions? looking for an efficent simple way to do...
|
by: manstey |
last post by:
Hi,
How do I convert a string like:
a="{'syllable': u'cv-i b.v^ y^-f', 'ketiv-qere': 'n', 'wordWTS': u'8'}"
into a dictionary:
b={'syllable': u'cv-i b.v^ y^-f', 'ketiv-qere': 'n', 'wordWTS':...
|
by: comp.lang.tcl |
last post by:
My TCL proc, XML_GET_ALL_ELEMENT_ATTRS, is supposed to convert an XML
file into a TCL list as follows:
attr1 {val1} attr2 {val2} ... attrN {valN}
This is the TCL code that does this:
set...
|
by: hiro |
last post by:
Hi there, I have a 2 lists.. for simplicities sake lets say the are:
l1 =
l2 =
what I need to do is compare l1 against l2 and return the "position"
of where each object in l1 is in l2
...
|
by: christophertidy |
last post by:
Hi
I am new to Python and have recieved this error message when trying to
instantiate an object from a class from another file within the same
directory and wondered what I have done wrong.
I...
|
by: rewonka |
last post by:
Hello,
I'm trying to find the fastest way to convert an sql result into a
dict or list.
What i mean, for example:
my sql result:
contact_id, field_id, field_name, value
sql_result=,
,
,
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |