Printing gives me a memory address on a class list rather than a specific STR
Date : March 29 2020, 07:55 AM
I wish did fix the issue. To get the list to print something other than the instance information you need to implement __repr__ on your Card class. The list container uses this function instead of __str__ to get the string representations for the objects it contains. This is mainly for debugging purposes and should uniquely identify the object. So...First I added the following to your Card class. def __repr__(self):
return '%s of %s' % (Card.rank_names[self.rank], Card.suit_names[self.suit])
# Printing the whole list (which uses __repr__)
j=Deck()
foo = j.deal_hands(2,3)
print foo
# Printing the lists (which uses __str__)
for hand in foo:
for card in hand:
print card
$ python test.py
[[King of Spades, Queen of Spades], [Jack of Spades, 10 of Spades], [9 of Spades, 8 of Spades]]
King of Spades
Queen of Spades
Jack of Spades
10 of Spades
9 of Spades
8 of Spades
import pprint
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(foo)
[ [King of Spades, Queen of Spades],
[Jack of Spades, 10 of Spades],
[9 of Spades, 8 of Spades]]
|
tail->next printing address instead of data circular linked list c++
Date : March 29 2020, 07:55 AM
seems to work fine Im trying to tie two ends together in my circular singly linked list. In the file name file.txt, containing ABCDEFGHIJKLMNOPQRSTUVWXYZ as text, I was able to print out the head and tail, A and Z, respectively. however, I'd like Z to point to A however my output is the address of A ( see below ). What am I doing wrong in addNode()? #include <string.h>
#include <cstdio>
#include <cstdlib>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream> // For file input
#include <cassert> // for assertions
using namespace std;
FILE *filename = fopen("file.txt", "r"); // Try to open file
struct Node
{
char data;
Node* next;
} ;
void addNode( Node * &head, Node * &tail, char input)
{
Node *pTemp = new Node;
pTemp->data = input;
if( head == NULL)
{
head=tail =pTemp;
tail->next=pTemp;
}
else
{
pTemp->next = tail->next;
tail->next=pTemp;
tail = pTemp;
}
}//end addNode()
int main()
{
assert(filename);
Node *head=NULL;
Node *tail=NULL;
char c =' ';
int i=0;
while( fscanf(filename,"%c", &c) != EOF)
addNode( head,tail, c);
cout<<endl;
cout<<"\nHead element is "<<head->data<<endl;
cout<<"Tail element is "<<tail->data<<endl;
cout<<"After tail '"<<tail->data<<"' is : "<< tail->next->data<<endl;
}
Node A
[A | pointer to self] <- head and tail
Node B
[A | pointer to B ] <-head
[B | pointer to A ] <-tail
Node C
[A | pointer to B ] <-head
[B | pointer to C ]
[C | pointer to A ] <-tail
Node D
[A | pointer to B ] <-head
[B | pointer to C ]
[C | pointer to D ]
[C | pointer to A ] <-tail
|
Printing an hexadecimal memory address of a node in a linked list in C
Date : March 29 2020, 07:55 AM
hop of those help? ¤tPtr give you a pointer to the pointer variable, it's not where currentPtr is actually pointing. The value of ¤tPtr will not change in the loop, since the variable itself will not change location. If you want to print where currentPtr is pointing, to the node itself, then print plain currentPtr.
|
Printing the list of unique first name last name phone number email and address details in excel using Python
Tag : python , By : Robert Daniel Pickar
Date : March 29 2020, 07:55 AM
may help you . We have created a python code to print "ABCD MNOP 282-567-4285 455 mindspace St., brisbane GA 35001 abcdmnop@gmail.com" which is nothing but First Name, Last Name, Mobile Number and Address , Try the following
import random
import xlsxwriter
first_names = ['ABCD', 'EFGH', 'IJKL', 'MNOP', 'QRST', 'UVWX', 'YZ']
last_names = ['ABCD', 'EFGH', 'IJKL', 'MNOP', 'QRST', 'UVWX', 'YZ']
street_names = ['indralok', 'mindspace', 'marine drive', 'kora kendra', 'bamdstand', 'mount mary', 'milan', 'paris','dubai', 'dindoshi', 'magathane', 'arnala']
cities_names = ['mumbai', 'banglore', 'pune', 'lucknow', 'patna', 'goa', 'ahmedabad', 'sydney', 'melbourne', 'brisbane','perth']
states = ['AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DC', 'DE', 'FL', 'GA', 'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY','LA', 'ME', 'MD', 'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'OH','OK', 'OR', 'PA', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY']
N = 10
workbook = xlsxwriter.Workbook('output.xlsx')
worksheet = workbook.add_worksheet()
def get_random_value(input_list):
return input_list[random.randint(0, len(input_list)-1)]
worksheet.write(0, 0, "First Name")
worksheet.write(0, 1, "Last Name")
worksheet.write(0, 2, "Street")
worksheet.write(0, 3, "City")
worksheet.write(0, 4, "State")
for i in range(1,N+1):
worksheet.write(i, 0, get_random_value(first_names))
worksheet.write(i, 1, get_random_value(last_names))
worksheet.write(i, 2, get_random_value(street_names))
worksheet.write(i, 3, get_random_value(cities_names))
worksheet.write(i, 4, get_random_value(states))
workbook.close()
|
printing reference variable is not printing the object's address
Tag : java , By : Ted Leung
Date : March 29 2020, 07:55 AM
|