take a string as a name for numeric variable or vector

This is the place for queries that don't fit in any of the other categories.

take a string as a name for numeric variable or vector

Postby Cyrille » Fri Jun 13, 2014 3:34 pm

Hello,

I try to fix a problem i have. I looked for solution but i didn't finis nothing about it (maybe i don't search well). In fact, i have some names in a string and i want to take these names as the name of some vector i have. For example:

The string :['name1', 'name2', 'name3']
3 vectors : [5, 3, 1]
[4, 1, 3]
[1, 3, 2]
and i want to call [5, 3, 1] with the variable name 'name1', [4, 1, 3] with the variable name 'name2',…

Actually i have a huge number of names and vectors corresponding. Some one can help me?

Thanks a lot!

Cyrille
Cyrille
 
Posts: 1
Joined: Fri Jun 13, 2014 3:23 pm

Re: take a string as a name for numeric variable or vector

Postby metulburr » Fri Jun 13, 2014 4:15 pm

To be honest, your whole post is quite confusing.

It appears you are trying to create a dictionary with a string as a key, and a list as the value?
Code: Select all
dictionary = {'name1':[5, 3, 1]}
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1470
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: take a string as a name for numeric variable or vector

Postby Crimson King » Fri Jun 13, 2014 4:24 pm

If what metulburr posted is what you wanted to do try this:

Code: Select all
dict(zip(names,vectors)) #change the variable names to match the ones in your code


By the way, read this: viewtopic.php?f=6&t=145
User avatar
Crimson King
 
Posts: 113
Joined: Fri Mar 08, 2013 2:42 pm
Location: Buenos Aires, Argentina


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 3 guests