Python Forum
Search Results
Post Author Forum Replies Views Posted [asc]
    Thread: [] vs *[]
Post: RE: [] vs *[]

Thanks vert much bowlofred. That does clearly explains the reasons behind the error. I also noticed a small performance differences between unpacking vs sending the list. To my surprise unpacking pe...
hshivaraj General Coding Help 3 1,273 Jan-29-2022, 04:45 PM
    Thread: [] vs *[]
Post: [] vs *[]

Hey guys what the different between sending a send as [] and *[]? For instance def main(): x = [1] * 10 print(list(chain(*x))) print(list(chain(x)))Error:Traceback (most recent call last...
hshivaraj General Coding Help 3 1,273 Jan-28-2022, 11:34 PM
    Thread: is and '==' i'm confused
Post: is and '==' i'm confused

Hi all >>> a = "this is test string" >>> b = "this is test string" >>> a == b True >>> a is b False >>> a = "test" >>> b = "test" >>>...
hshivaraj General Coding Help 6 2,720 Sep-12-2021, 02:58 PM
    Thread: Dtype STR but output in Shell still int?
Post: RE: Dtype STR but output in Shell still int?

Thanks. Thats the source code. But i was asking for the CSV file your reading?
hshivaraj General Coding Help 6 2,277 Oct-04-2020, 01:18 PM
    Thread: Store a set in a dictionary's value
Post: RE: Store a set in a dictionary's value

Something like this? from collections import defaultdict def get_dict(team_list): year = 1903 winning_dict = defaultdict(set) for index in team_list: winning_dict[index].add(yea...
hshivaraj General Coding Help 9 3,219 Oct-04-2020, 01:17 PM
    Thread: Dtype STR but output in Shell still int?
Post: RE: Dtype STR but output in Shell still int?

Could you show us the first few lines of your CSV file?
hshivaraj General Coding Help 6 2,277 Oct-04-2020, 01:11 PM
    Thread: Coin Toss - Distribution
Post: RE: Coin Toss - Distribution

Frankly I dont see what the script is doing. Your using variable x twice which is going to cause issues. Remember tail as a list is created every time for the outer loop and in the inner loop being m...
hshivaraj General Coding Help 6 3,122 Oct-04-2020, 01:02 PM
    Thread: Graph identifier
Post: RE: Graph identifier

This is jjst a brut force method with no complications. Let for instance assume that movements are stores in a list mov1 = [10000, 10120, 10080, 9990, 10050, 10210] The next step is to find the di...
hshivaraj General Coding Help 4 2,669 Oct-04-2020, 12:52 PM
    Thread: Coin Toss - Distribution
Post: RE: Coin Toss - Distribution

Negative indexing reads value from backwards. For instance >>> a = [1, 2, 3] >>> a[-1] 3 >>> a[-2] 2 >>> a[0] 1 >>> a[1] 2I hope that give some explanati...
hshivaraj General Coding Help 6 3,122 Oct-04-2020, 12:33 PM
    Thread: Global not working why?
Post: RE: Global not working why?

Firstly I find your code hard to read and there is no clear flow to it. Its interesting that you have acknowledged that global s are bad, but yet you've used extensively. And I dont buy into the argum...
hshivaraj General Coding Help 13 4,445 Oct-04-2020, 12:30 PM
    Thread: Whats a good design/approach?
Post: Whats a good design/approach?

Hi all. I have this simple code, which does pretty simple things as open a file within the class. But i cant decide what the best design. Is approach1 is better approach2? I need to understand when ...
hshivaraj General Coding Help 1 1,780 Sep-15-2019, 10:11 PM
    Thread: Token and auth-token
Post: Token and auth-token

Hey all. I have problem which i dont quite understand how to go about from here. I use request library to sign-in to website and I believe im doing that right. I make a post request to /sign-in page ...
hshivaraj Web Scraping & Web Development 1 2,878 Jul-24-2019, 04:30 PM
    Thread: How do i write tests for this code?
Post: How do i write tests for this code?

Hi all. I wrote a sample code recently. And I want to write some tests and I cant get my head around if I got my structure right. I have a few question. I know there many of you here much experience...
hshivaraj General Coding Help 0 2,024 Apr-27-2019, 05:28 PM
    Thread: VM address (C pointer) of Python object
Post: RE: VM address (C pointer) of Python object

Do you mean id() function in python?
hshivaraj General Coding Help 1 2,053 Apr-21-2019, 10:57 PM
    Thread: Dictionary Results Error
Post: RE: Dictionary Results Error

Dont provide the reference. Instead just the value should suffic. Remove the *. Read about how to use * in python print('| {:14} | {:11} | {:16} | {:15} |'.format(key, *value))
hshivaraj General Coding Help 2 2,270 Apr-21-2019, 10:53 PM
    Thread: swap elements in list
Post: swap elements in list

Hi all So the only way i can think of to swap two elements in list with the following def swap(arr, pos1, pos2):I wonder if there is away where I dont have to send the position of elements to be swa...
hshivaraj General Coding Help 3 12,545 Apr-21-2019, 10:50 PM
    Thread: Why is this pointing to the objects
Post: RE: Why is this pointing to the objects

That's brilliant. I feeling very stupid to have not tried that before. And thinking of performance first. But many thanks :)
hshivaraj General Coding Help 6 2,848 Apr-09-2019, 10:55 PM
    Thread: Cant get my head round the algorithm
Post: Cant get my head round the algorithm

Hi all. Wonder anyone here can help to get the algorithm right. I have sorted list of numbers and I need to pair of numbers which add to target or close to target. For instance List 500 700 1000 14...
hshivaraj General Coding Help 1 2,326 Apr-09-2019, 10:29 PM
    Thread: Why is this pointing to the objects
Post: RE: Why is this pointing to the objects

This really is interesting. My illusion was that anything within the class block would be instance variable. It appears from what your demonstrating is that unless you but anything within the construc...
hshivaraj General Coding Help 6 2,848 Apr-09-2019, 08:10 PM
    Thread: Why is this pointing to the objects
Post: RE: Why is this pointing to the objects

(Apr-09-2019, 07:44 PM)Gribouillis Wrote: There is really nothing to understand here: variables stored in the class object A, such as A.l are shared by all the instances of that class. Sure - that e...
hshivaraj General Coding Help 6 2,848 Apr-09-2019, 07:47 PM

User Panel Messages

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