[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
halp
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 32
Thread images: 1
How do I create and assign thousands of variables in a while loop in python?
>>
>>55172713

>What's a list
>>
>>55172745
I'm assigning lists to the variables ,genius.
>>
>>55172764
>What's a list of lists
>>
>>55172905
I'm assigning them to list of lists.
>>
>>55172932
Go deeper then. List of lists of lists. The only limit is your RAM. Any time you're looking at var001 through var999, you're better off with an array.
>>
You are doing something wrong.
>>
https://docs.python.org/2/c-api/reflection.html

var1
var2
varX

Use reflection to create and init the variables. Using a loop is implied.
>>
>>55172713

>How do I create and assign thousands of variables

You should probably think about your desing..

Id'd put it in a two-dimensional array:

myArray=[[i*j for j in range(10)] for i in range(10)]

for i in range(len(myArray)):
for j in range(len(myArray[i])):
print myArray[i][j]



If that's not possible you might think about using a differnt data structure (i.e. a list) and manage the lists in a meta data structure, as the other anon has suggested.
>>
>>55172764
guess you don't need any help then ,genius.
>>
It's simple, just use spreadsheet program to generate the assignment statements and then copy/paste them into your python code file.
>>
>>55173116
this
>>
>>55172764
>>55173447
thats not how commas work
>>
>>55172713
You shouldn't have to.
Tell us what exactly you want to do, and maybe we can tell you a better way of doing it
>>
>>55173664
I'm designing a speechbot which fetches speeches and quotes from the internet and separates them word by word .it mixes speeches and brute forces combinations which makes sense.I know i'm doing something wrong but I want to do it anyway.
>>
>>55174166
*Why* do you want to use crazy named variables rather than arrays?
>>
>>55173653
its exactly how commas work, niggerface autist
>>
>>55174367
no it,s not
>>
>>55174166
Lol... why are you not just using a list of strings? If you need searching or other properties then use a hash with a custom data structure.
>>
>>55172713
New averaging system, eh? You're doing something horribly wrong.
>>
>>55174406
>55174406
I already have list of list of all the strings. How can create different string on the basis of appearance? i.e first word,second word...
I thought I should create variables each word and append them to a new list on the basis of their index.
Is there a better way? Sorry if I sound like a retard.
>>
>>55174522
Anywhere you'd use a custom named variable, use an array with an index.

Instead of
output[i] = var123
do
output[i] = words[123]

Or
output = ""
...
output += words[123] + " "
>>
Use a Map or a Dict.
>>
>>55174386
fuck off,
>>
>>55174408

Sick reference bro, your references are out of control.
>>
>>55172713
>How do I create and assign thousands of variables in a while loop in python?

You don't because that's fucking retarded.
>>
This thread is hilarious.
>>
>using for loops in Python
senpai...
>>
>>55172713
God and God spelled backwards?
>>
what you need:
words = {}
word['gif'] = 'jif'
print(word['gif'])

what you want:
exec(' gif = "jif" ')
print(gif)
>>
>>55179085
this
just use vectorization for literally all for loops
>>
>>55172713
install gentoo
Thread replies: 32
Thread images: 1

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.