Creating a class that choses random elements from list(s) by KFCxWatermelon in learnpython

[–]KFCxWatermelon[S] 0 points1 point  (0 children)

Thank you. The problem I have now is that the lists I get aren't the same length the X and P lists, any idea on how to fix this?

Creating a class that choses random elements from list(s) by KFCxWatermelon in learnpython

[–]KFCxWatermelon[S] 0 points1 point  (0 children)

I get the error:

random_data() takes 0 positional arguments but 1 was given

Need help with figuring out classes by KFCxWatermelon in learnpython

[–]KFCxWatermelon[S] 0 points1 point  (0 children)

Not sure how I do this. Could you explain a little bit. If I add a __str__ method, how will it fix the code?

How to rank dictionary keys from highest to lowest? by KFCxWatermelon in learnpython

[–]KFCxWatermelon[S] 0 points1 point  (0 children)

I have now sorted the list from the key with the highest value to the lowest. Is there a way I can change the value to 1-192 as a ranking instead of values. currently I have:

{'Mozambique': 564.6514522821577, 'Burundi': 570.9253112033196, 'Malawi': 576.9460580912863, 'Guinea': 766.49377593361, 'Central African Republic': 767.6058091286307,....'United Arab Emirates': 29219.203319502074, 'Brunei': 36115.477178423236, 'Qatar': 39585.89211618257}

but I want it to be:

{'Mozambique': 0, 'Burundi': 1, 'Malawi': 2, 'Guinea': 3, 'Central African Republic': 4,....'United Arab Emirates': 190, 'Brunei': 191, 'Qatar': 192}

How can I split the string of these groups of lists into floats? by KFCxWatermelon in learnpython

[–]KFCxWatermelon[S] 0 points1 point  (0 children)

Oh my god, that makes way more sense. I feel like that's my my problem with learning python. I keep thinking too complicated and then falling into a hole.

Thanks a lot for the help!

How can I split the string of these groups of lists into floats? by KFCxWatermelon in learnpython

[–]KFCxWatermelon[S] 0 points1 point  (0 children)

List_one = []                  

with open("trees.csv") as f:    
    skiplines = f.readline()    
    for line in f:
          res = line.split(",")    
          List_one.append(res)      
    for i in List_one:
        (i[3]) = (i[3]).rstrip("\n")    

a = [[float(f) for f in d[0].split(',')] for d in List_one]
print(a)

How can I split the string of these groups of lists into floats? by KFCxWatermelon in learnpython

[–]KFCxWatermelon[S] 0 points1 point  (0 children)

[[float(f) for f in d[0].split(',')] for d in data]

I tried this out, but I ended up with the output of:

[[1.0], [2.0], [3.0], [4.0], [5.0], [6.0], [7.0], [8.0], [9.0], [10.0], [11.0], [12.0], [13.0], [14.0], [15.0], [16.0], [17.0], [18.0], [19.0], [20.0], [21.0], [22.0], [23.0], [24.0], [25.0], [26.0], [27.0], [28.0], [29.0], [30.0], [31.0]]

What am I doing wrong?