Python Forum
Search Results
Post Author Forum Replies Views Posted [asc]
    Thread: auto increment
Post: RE: auto increment

I would name the class Counter.
LeSchakal General Coding Help 7 14,385 Nov-02-2018, 10:52 PM
    Thread: Caesar Cypher--- I don't understand why it doesn't work
Post: RE: Caesar Cypher--- I don't understand why it doe...

(Nov-02-2018, 09:42 PM)ironsheep Wrote: You understood what I was trying to do, how come computers can't?? You told us more or less, what you're trying to do, but you have to explain it to the compu...
LeSchakal General Coding Help 12 5,864 Nov-02-2018, 10:15 PM
    Thread: Python arrays
Post: RE: Python arrays

It seems that your data2 is not a list of strings but a nested list. # a list: data2 = ['1','2','3','4'] # a nested list: data2 = [['1','2'],['3','4']]
LeSchakal Homework 3 3,138 Oct-31-2018, 12:51 AM
    Thread: Return giving incorrect value
Post: RE: Return giving incorrect value

(Oct-24-2018, 09:17 PM)nilamo Wrote: We must have different opinions on the definition of very. I thought it was better to count a non-int as an invalid entry then to let the program crash.
LeSchakal Homework 5 3,335 Oct-24-2018, 09:53 PM
    Thread: Return giving incorrect value
Post: RE: Return giving incorrect value

(Oct-18-2018, 05:30 PM)Larz60+ Wrote: new get_miles function (replaces miles to kms) def get_miles(): attempts = 0.0 attempts += 1 miles = -1 # initialize miles while True: ...
LeSchakal Homework 5 3,335 Oct-24-2018, 09:16 PM
    Thread: making a dictionary from a list, one key with multiple values in a list within a list
Post: RE: making a dictionary from a list, one key with ...

If you're using Python 2.7 or higher, PEP 274 -- Dict Comprehensions may help you. lst = [['Helloworld', 'W', 'R'], ['pinglog', 'W'], ['data', 'X', 'W', 'R']] my_dict = {item[0] : item[1:] for item i...
LeSchakal Homework 4 3,571 Oct-24-2018, 06:40 PM
    Thread: finding 2 max values in an array in python
Post: RE: finding 2 max values in an array in python

(Oct-17-2018, 09:17 PM)nilamo Wrote: Ok, but because you use .index(), it's slower the more results you want (I believe O(n) is what it'd be called). For example, if you change it to be 1) an unsort...
LeSchakal General Coding Help 11 184,039 Oct-17-2018, 09:43 PM
    Thread: finding 2 max values in an array in python
Post: RE: finding 2 max values in an array in python

I've tried this: from operator import itemgetter def n_max(seq, n=2): max_items = sorted(enumerate(seq), key=lambda x: x[1])[-1 * n:] return max_items[::-1] def my_max(seq, n=2): max_va...
LeSchakal General Coding Help 11 184,039 Oct-17-2018, 08:56 PM
    Thread: finding 2 max values in an array in python
Post: RE: finding 2 max values in an array in python

Assuming your array has only unique values: max_values = sorted(your_array, reverse=True)[:2] indices = [your_array.index(value) for value in max_values]
LeSchakal General Coding Help 11 184,039 Oct-17-2018, 07:54 PM

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020