473,382 Members | 1,519 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How to justify a container is a list or dictionary?

1
Hi,
Now i raise a question : How to justify a container is a list or dictionary?

thank you for your answer !

Ma Shuai
Oct 10 '07 #1
4 1587
ilikepython
844 Expert 512MB
Hi,
Now i raise a question : How to justify a container is a list or dictionary?

thank you for your answer !

Ma Shuai
I think there is a type function that is built in which gives the type pf the object.
Oct 10 '07 #2
Motoma
3,237 Expert 2GB
I am sure there is a much more elegant way of doing this (there always is), but here I go anyway:

Expand|Select|Wrap|Line Numbers
  1. >>> a = [1, 2, 3, 4, 5]
  2. >>> b = dict()
  3. >>> b['a'] = 1
  4. >>> b['b'] = 2
  5. >>> type(a)
  6. <type 'list'>
  7. >>> type(b) == type([])
  8. False
  9. >>> type(b) == type(dict())
  10. True
  11. >>> 
  12.  
Oct 10 '07 #3
bvdet
2,851 Expert Mod 2GB
Here is another way using isinstance():
Expand|Select|Wrap|Line Numbers
  1. >>> seq = [1,2,3,4,5]
  2. >>> dd = dict(zip(seq, ['a','b','b','d','e']))
  3. >>> isinstance(seq, list)
  4. True
  5. >>> isinstance(dd, dict)
  6. True
  7. >>> isinstance(seq, dict)
  8. False
  9. >>> 
Oct 10 '07 #4
Motoma
3,237 Expert 2GB
Here is another way using isinstance():
Expand|Select|Wrap|Line Numbers
  1. >>> seq = [1,2,3,4,5]
  2. >>> dd = dict(zip(seq, ['a','b','b','d','e']))
  3. >>> isinstance(seq, list)
  4. True
  5. >>> isinstance(dd, dict)
  6. True
  7. >>> isinstance(seq, dict)
  8. False
  9. >>> 
Nice!
See, that is why I participate in threads like this, I get to learn neat little tricks :D
Oct 10 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: The Plankmeister | last post by:
Ello... Is there a way to recreate the "text-align : justify" behaviour with images? (add to wish list: "image-align : justify") I have a gallery page and would like all the images to properly...
3
by: pecan | last post by:
I've been trying to justify some text: when I align it left or right or centre, it works, but when I align it to justify it ignores me. I've tried overriding the CSS by justifying withing the html...
6
by: buzzweetman | last post by:
Many times I have a Dictionary<string, SomeTypeand need to get the list of keys out of it as a List<string>, to pass to a another method that expects a List<string>. I often do the following: ...
3
by: erik gartz | last post by:
Hello, I'm new to python and I'm having difficulty understanding the following code. Why doesn't the variable a contain , ] instead. Doesn't {} allocate new memory for the dictionary each time?...
3
by: Cristiano Paris | last post by:
Hi everyone, I'm trying to write a Container which should mimic a list. Basically, the container pulls items on the fly from an unspecified source through a function and returns an instance of a...
7
by: Andrew Robinson | last post by:
I have a method that needs to return either a Dictionary<k,vor a List<v> depending on input parameters and options to the method. 1. Is there any way to convert from a dictionary to a list...
4
by: =?Utf-8?B?SnVlcmdlbiBELg==?= | last post by:
When I try to run this following small code sample: using System; using System.Collections.Generic; class Program { static void Main(string args) { Dictionary<string, intMyDict = new...
5
by: tshad | last post by:
I have a datagrid that I cannot get to right justify a money amount (which is just a label). No matter what I do - it still right justifies it. <asp:TemplateColumn Visible="true"...
12
by: =?Utf-8?B?THVpZ2k=?= | last post by:
Hi all, I have a dictionary like this: Dictionary<List<string>, List<string>> How can I iterate in it? Thanks very much. -- Luigi
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.