Python linked list- Nonetype error in recursive remove function

I am teaching myself Python and working through the construction of a singly linked list class. The class constructors, add, and display functions all work, but when trying to implement a recursive remove function, I find that either the list does not change at all, or it deletes itself entirely. Adding print statements into the recursive function that are intended to print the value of the node generate Nonetype attribute errors, which suggest to me that I may have an issue with the arguments being passed in, as the object that I think is a node is apparently not. I’ve reviewed the other Nonetype questions I’ve found on SE, but either they haven’t shed the needed light or I’ve just misunderstood them.
Class Definitions:

class Node:
    def __init__(self, value):
        self.data = value
        self.next_node = None
        
class List:
    def __init__(self):
        self.head = None

Remove functions:

def remove(self, target):
     if(self.head == None):
          print("List is empty!")
          return None
     else:
          print(str(self.head.data))
          self.head = self.remove_target(self.head, target)
          return self.head
        
def remove_target(self, head, target):
     print("Target: " + str(target) + "Head: " + str(head.data)) #Nonetype errors occur here
     if(head == None):
          return head
     if(head.data == target):
          print("target found")
          head = head.next_node
          return head
     else:
          head.next_node = self.remove_target(head.next_node, target)
          return head

My previous programming experience is in c++, and I think part of the problem is that wrapper functions used to hide data members in c++ aren’t really a thing in Python? However, the same results occur when I call the recursive function directly from the test program. Any light that can be shed would be most appreciated!

java – linked list and stack implementation clarification (singly and normal list)

I ran into a local programming challenge yesterday and I ask for:

is it possible to create a normal linked list (insert in tail section
and remove from front) with two stack or any other number of stack?

I dont know how this be possible because stack is LIFO. is there any idea? this is a wrong question?

css – WordPress – Linked image displaying differently on Front-End, then when opening the link via new tab

So I have a staging site here:

Főoldal

If you scroll down a bit, you see a section in the sidebar called “Árfolyamok”.
See screenshot: https://www.dropbox.com/s/p37d3llpmj7wa0r/Screenshot%202021-01-15%20at%2011.54.36.png?dl=0

Now here’s the black magic part:
If I right click on this image, and either copy or open in a new tab, I get the same image, but the gray background is black instead, see screenshot:

https://tozsdeforum.ethermedia.hu/wp-content/uploads/FeedCache/images/MOL_1610708076.png

It seems as if some sort of filter would do this, but I can’t find in anything in the css that would do this. Anyone have an idea why?

Thanks!

If a page has fewer external links, will the linked pages get more SEO benefit?

Does it matter whether a page externally links to 1 or 10 pages, from the POV of the pages linked? Would they somehow receive lesser SEO benefits as in less visibility or link juice (even though I think that term is now obsolete)

Google Sheet script will not run on a tab linked to a Google Form

I wrote a script to move a row of data from one sheet (Sheet1) to another (Sheet2) when I type the word Yes in column one. I can get the script to work perfectly when the sheet is not collecting Form responses. When I have the first tab attached to a form my script will not run. Can someone please tell me what would prevent the script from running on a tab that is collecting responses?

permissions – Unable to delete folders or files in SharePoint site linked to a Team

I am unable to delete folders or documents in a SharePoint library that is linked to a particular MS Team. When I click on the ellipses of a folder or file the delete option is not there (it is there for other SharePoint/teams libraries).

I have checked to see if there are any files checked out and there are none.

I have managed to delete the folder by going into Classic SharePoint view and the deleting via the files tab. But I am just confused as to why I couldn’t delete them in the normal way. I have checked the settings for the site and can’t see anything out of the ordinary.

Any help would be appreciated!

linked lists – Writing a C program that reads data.txt and reverses the order of odd numbers

Can you help me with this question please? I tried everything but couldn’t do it myself. I couldn’t find a similar question on the internet so I had to ask it myself.

Write a C program that reads a line from data.txt and creates a singly linked list queue from it. This C program changes that queue order by reversing the order of the odd integers while leaving the even integers in place.
Run this program for each line of the data.txt file and print out the results.
The first line of the data.txt file contains the sample count.

Use Singly Linked List, not Array! Solution is based on stack and queue combination.

For example given this queue:
14 13 17 8 4 10 11 4 15 18 19 //queue 1 2 3 4 5 //order of the odd integers

program would change it to:
14 19 15 8 4 10 11 4 17 18 13 //queue 5 4 3 2 1 //order of the odd integers

This is the data file:

Data.txt

Thank you in advance.

c – Why doesn’t the linked list program print anything? Can the code in my insert() be shorter?

it only prints 5 which is the first node.

If there’s a better way to implement a linked list, that might be what I need.

(order of the below linked list is sorted by value)

#include<stdio.h>
#include<stdlib.h>
typedef struct node{
    int value;
    struct node* next;
}node;

node* first=NULL;
node* last=NULL;

void insert(int value){
    
    node* temp2=malloc(sizeof(node));
    temp2->value=value;
    
    if(last==NULL){
        first=last=temp2;
        temp2->next=NULL;
        return;
    }
    node* temp=last;

    while(!(temp->value<value && (temp->next->value>value||temp->next==NULL)))
        temp=temp->next;
    
    temp2->next=temp->next;
    
    if(last->value>=value){//if the value is the smallest
        last=temp2;
        return;
    }
    temp->next=temp2;
}
int main(){
    insert(5);
    printf("%d ",last->value);
    insert(3);
    printf("%d ",last->value);
}

dnd 5e – Can a kalashtar’s linked quori spirit be seen using truesight?

In various depictions of kalashtar, the quori spirit that they are merged with/linked to is seen behind them or occupying the same space, sometimes echoing their movement or stance. Is this purely artistic licence, or is there some truth to the representation? Would this sight be perceptible through any magic or senses?

linked list – Removing C comments from Source

Challenge posted 5 Dec 2020 to comp.lang.c by Tim Rentsch This program is essentially the same as my Version 8 posted to that thread, but with some further cosmetic improvements.

This program reads from stdin (or a named file) and writes its result to stdout, removing C comments from the text. It has to see through any sequences of BACKSLANT NEWLINE when detecting comments, but reproduce all such line continuation sequences that were not part of a comment. Additionally, the challenge was to use no gotos and reasonably short functions.

The code was originally inspired by a Haskell program and it implements a simple Lisp-ish data structure including a simple garbage collector. I don’t want to explain much more because I want the code to speak for itself.

strpcom-v5.c

//strpcom-v5.c:
//$ make strpcom-v5 CFLAGS='-std=c99 -Wall -pedantic -Wextra -Wno-switch'

#ifndef DEBUG_LEVEL
#define DEBUG_LEVEL 0
#endif
static const int debug_level = DEBUG_LEVEL;
static const int handle_roots = 1;


#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


typedef union uobject *object;
typedef object list;
typedef enum tag { INVALID, INTEGER, LIST } tag;
#define OBJECT(...) new_( (union uobject()){{ __VA_ARGS__ }} )

union uobject { tag t;
       struct { tag t; int i, continues; } Int;
       struct { tag t; object a, b; } List;
};

typedef struct record {
  int mark;
  struct record *prev;
  object *handle;
  union uobject o;
} record;


static void     init_patterns();
static void     cleanup();
static list     chars_from_file( FILE *f );
static list     logical_lines( list o );
static list       trim_continue( list o, list tail );
static list     restore_continues( list o );
static list     strip_comments( list o );
static list       single_remainder( list tail );
static list       multi_remainder( list tail );
static int        starts_literal( object a );
static list       literal_val( object a, list o );
static list     skip_quote( object q, list o );
static list     nested_comment( list o );
static void     print( list o, FILE *f );

static object   Int( int i );
static list     cons( object a, object b );
static list     one( object a );
static object   car( list o );
static object   cdr( list o );
static int      eq( object a, object b );
static int      eqint( object a, int i );
static int      match( object pat, object it, object *matched, object *tail );

static object   add_global_root( object o, object *op );
static int      collect( object local_roots );
static void       mark( object ob );
static int        sweep( record **ptr );
static record *   alloc();
static object   new_( object a );
static int      error( char *msg );


record *allocation_list;
object global_roots;
list   slnl; // patterns
list   single,
       multi;
list   starsl;

int
main( int argc, char **argv ){
  init_patterns();
  list input = chars_from_file( argc > 1  ? fopen( argv(1), "r" )  : stdin );
  if(  debug_level >= 2  )
    fprintf( stderr, "input:n"), print( input, stderr );

  list logical = logical_lines( input );
  if(  debug_level >= 2  )
    fprintf( stderr, "logical:n"), print( logical, stderr );

  list stripped = strip_comments( logical );
  if(  debug_level >= 2  )
    fprintf( stderr, "stripped:n"), print( stripped, stderr );

  list restored = restore_continues( stripped );
  if(  debug_level >= 2  )
    fprintf( stderr, "restored:n");

  print( restored, stdout ), fflush( stdout );
  cleanup( restored ), input = logical = stripped = restored = NULL;
}

void
init_patterns(){
  slnl   = add_global_root( cons( Int( '\' ), one( Int( 'n' ) ) ), &slnl );
  single = add_global_root( cons( Int( '/' ), one( Int( '/' ) ) ), &single );
  multi  = add_global_root( cons( Int( '/' ), one( Int( '*' ) ) ), &multi  );
  starsl = add_global_root( cons( Int( '*' ), one( Int( '/' ) ) ), &starsl ); 
}

void
cleanup( object restored ){
  if(  debug_level  ){
    if(  debug_level >= 2  ) fprintf( stderr, "@%dn", collect( restored ) );
    if(  handle_roots  ){ global_roots = NULL; }
    fprintf( stderr, "@%dn", collect( NULL ) );
  }
}

list
chars_from_file( FILE *f ){
  int c = fgetc( f );
  return  c != EOF  ? cons( Int( c ),
                            chars_from_file( f ) )
       :  one( Int( c ) );
}


list
logical_lines( list o ){
  if(  !o  ) return  NULL;
  if(  debug_level >= 2 && car(o)->Int.i != EOF  )
      fprintf( stderr, "(%c%c)", car(o)->Int.i, car(cdr(o))->Int.i );
  object matched, tail;
  return  match( slnl, o, &matched, &tail )  ? trim_continue( o, tail )
       :  cons( car( o ),
                logical_lines( cdr( o ) ) );
}

list
trim_continue( list o, list tail ){
  if(  debug_level >= 2  ) fprintf( stderr, "@" );
  return  car( tail )->Int.continues = car( o )->Int.continues + 1,
          logical_lines( tail );
}

list
restore_continues( list o ){
  return  !o  ? NULL
       :  car( o )->Int.continues-->0  ?
            cons( Int( '\' ),
                  cons( Int( 'n' ),
                        restore_continues( o ) ) )
       :  cons( car( o ),
                restore_continues( cdr( o ) ) );
}

list
strip_comments( list o ){
  if(  !o  ) return  NULL;
  if(  debug_level >= 2 && car(o)->Int.i != EOF  )
      fprintf( stderr, "<%c%c>", car(o)->Int.i, car(cdr(o))->Int.i );
  object matched, tail;
  object a;
  return  match( single, o, &matched, &tail )  ? single_remainder( tail )
       :  match( multi, o, &matched, &tail )   ? multi_remainder( tail )
       :  starts_literal( a = car( o ) )       ? literal_val( a, cdr( o ) )
       :  cons( a,
                strip_comments( cdr( o ) ) );
}

list
single_remainder( list tail ){
  if(  debug_level >= 2  ) fprintf( stderr, "@/" );
  object c;
  for(  c = car( tail );
        tail && ! (eqint( c, 'n' ) || eqint( c, EOF ));
        c = car( tail = cdr( tail ) )  )
    ;
  return  eqint( c, 'n' )  ? cons( Int( 'n' ),
                                    strip_comments( cdr( tail ) ) )
       :  tail;
}

list
multi_remainder( list tail ){
  if(  debug_level >= 2  ) fprintf( stderr, "@*" );
  return  cons( Int( ' ' ),
                strip_comments( nested_comment( tail ) ) );
}

int
starts_literal( object a ){
  return  eqint( a, ''' ) || eqint( a, '"' );
}

list
literal_val( object a, list o ){
  return  cons( a,
                skip_quote( a, o ) );
}

list
nested_comment( list o ){
  if(  !o  ) error( "Unterminated commentn" );
  if(  debug_level >= 2  )
    fprintf( stderr, "(%c%c)", car( o )->Int.i, car( cdr( o ) )->Int.i );
  object matched, tail;
  return  match( starsl, o, &matched, &tail )  ? tail
       :  eqint( car( o ), EOF )               ? error( "Unterminated commentn" ),NULL
       :  nested_comment( cdr( o ) );
}

list
skip_quote( object q, list o ){
  if(  !o  ) error( "Unterminated literaln" );
  object a = car( o );
  return  eqint( a, '\' )  ? cons( a, 
                                    cons( car( cdr( o ) ),
                                          skip_quote( q, cdr( cdr( o ) ) ) ) )
       :  eq( a, q )        ? cons( a,
                                    strip_comments( cdr( o ) ) )
       :  eqint( a, 'n' )
       || eqint( a, EOF )   ? error( "Unterminated literaln" ),NULL
       :  cons( a,
                skip_quote( q, cdr( o ) ) );
}

void
print( list o, FILE *f ){
  switch(  o  ? o->t  : 0  ){
    case INTEGER: if(  o->Int.i != EOF  ) fputc( o->Int.i, f );
                  break;
    case LIST: print( car( o ), f );
               print( cdr( o ), f ); break;
  }
}


object
Int( int i ){
  return  OBJECT( .Int = { INTEGER, i } );
}

list
cons( object a, object b ){
  return  OBJECT( .List = { LIST, a, b } );
}

list
one( object a ){
  return  cons( a, NULL );
}

object
car( list o ){
  return  o && o->t == LIST  ? o->List.a  : NULL;
}

object
cdr( list o ){
  return  o && o->t == LIST  ? o->List.b  : NULL;
}

int
eq( object a, object b ){
  return  !a && !b         ? 1
       :  !a || !b         ? 0
       :  a->t != b->t     ? 0
       :  a->t == INTEGER  ? a->Int.i == b->Int.i
       :  !memcmp( a, b, sizeof *a );
}

int
eqint( object a, int i ){
  union uobject b = { .Int = { INTEGER, i } };
  return  eq( a, &b );
}

int
match( object pat, object it, object *matched, object *tail ){
  if(  !pat  ) return  *tail = it,  1;
  if(  pat->t != (it  ? it->t  : 0)  ) return  0;
  switch(  pat->t  ){
    case LIST: {
        object sink;
        if(  match( car( pat ), car( it ), & sink, tail )  )
          return  *matched = it,
                  match( cdr( pat ), cdr( it ), & sink, tail );
      } break;
    case INTEGER:
      if(  eq( pat, it )  ) return  *matched = it,  1;
  }
  return  0;
}


object
add_global_root( object o, object *op ){
  if(  handle_roots  ){
    global_roots = cons( o, global_roots );
    record *r = ((void*)( (char*)o - offsetof( record, o ) ) );
    r->handle = op;
  }
  return  o;
}

void
mark( object ob ){
  if(  !ob  ) return;
  record *r = ((void*)( (char*)ob - offsetof( record, o ) ) );
  if(  r->mark  ) return;
  r->mark = 1;
  switch(  ob  ? ob->t  : 0  ){
    case LIST: mark( ob->List.a ); mark( ob->List.b ); break;
  }
}

int
sweep( record **ptr ){
  int count = 0;
  while(  *ptr  ){
    if(  (*ptr)->mark  ){
      (*ptr)->mark = 0;
      ptr = &(*ptr)->prev;
    } else {
      record *z = *ptr;
      if(  z->handle  ) *z->handle = NULL;
      *ptr = (*ptr)->prev;
      free( z );
      ++count;
    }
  }
  return  count;
}

int
collect( object local_roots ){
  mark( local_roots );
  mark( global_roots );
  return  sweep( &allocation_list );
}

record *
alloc(){
  return  calloc( 1, sizeof(record) );
}

object
new_( object a ){
  record *r = alloc();
  object p = NULL;
  if(  r  ){
    r->prev = allocation_list;
    allocation_list = r;
    p = (void*)( ((char*)r) + offsetof( record, o ) );
    *p = *a;
  }
  return  p;
}

int
error( char *msg ){
  fprintf( stderr, "%s", msg );
  exit( EXIT_FAILURE );
  return 0777;
}

The repository includes a testing script, but due to some bash quirks it reports some false negatives so I don’t wish to display the results here. Compiling with DEBUG_LEVEL defined to 1 or higher will run a garbage collection at the end. Running under valgrind including the GC reports zero memory leaks.

Questions: Is is easy to discern the top-level structure? Are the individual functions readable/maintainable? Is it overkill to include a GC that doesn’t even run under normal compilation? Are there any functions where it’s possible to rewrite in a tail-recursive form to potentially reduce the function call depth?