Hi,
Now i raise a question : How to justify a container is a list or dictionary?
thank you for your answer !
Ma Shuai
4 1588
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.
I am sure there is a much more elegant way of doing this (there always is), but here I go anyway: -
>>> a = [1, 2, 3, 4, 5]
-
>>> b = dict()
-
>>> b['a'] = 1
-
>>> b['b'] = 2
-
>>> type(a)
-
<type 'list'>
-
>>> type(b) == type([])
-
False
-
>>> type(b) == type(dict())
-
True
-
>>>
-
bvdet 2,851
Expert Mod 2GB
Here is another way using isinstance(): - >>> seq = [1,2,3,4,5]
-
>>> dd = dict(zip(seq, ['a','b','b','d','e']))
-
>>> isinstance(seq, list)
-
True
-
>>> isinstance(dd, dict)
-
True
-
>>> isinstance(seq, dict)
-
False
-
>>>
Here is another way using isinstance(): - >>> seq = [1,2,3,4,5]
-
>>> dd = dict(zip(seq, ['a','b','b','d','e']))
-
>>> isinstance(seq, list)
-
True
-
>>> isinstance(dd, dict)
-
True
-
>>> isinstance(seq, dict)
-
False
-
>>>
Nice!
See, that is why I participate in threads like this, I get to learn neat little tricks :D
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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:
...
|
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?...
|
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...
|
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...
|
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...
|
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"...
|
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
|
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: 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: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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: 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...
| |