Naruto
Naruto

Reputation: 139

How to populate List datatype in the list

I want to populate the datatype of the list element into the List.

A=['X',123,'Xcw-123','ABC-er']
B=['string','int','string','string']

I tried to create this using type like.

A=[type(i) for i in A]

But I am getting list like:

[<class 'str'>, <class 'int'>, <class 'str'>,<class 'str'>]

Anyone suggest me another approach for this.

Upvotes: 0

Views: 59

Answers (1)

mhhabib
mhhabib

Reputation: 3121

AA = [type(i).__name__ for i in A]
print(AA)

Output

['string', 'int', 'string', 'string']

Upvotes: 1

Related Questions