Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 have homework to add a list to a list using append.
#1
So I am attempting to add a list to a list with append, but I don't think it is working, as I cannot call the list back out using another option. This is the list here:

passwords = [["yahoo","XqffoZeo"],["google","CoIushujSetu"]]
This is the code to attempt to add the two inputs as a list:

if(choice == '3'):
        print("What website is this password for?")
        website = input()
        print("What is the password?")
        unencryptedPassword = input()
There are other choices, but they aren't important at the moment. Finally my code attempting to add the inputs to the list, as a list using append, I should also mention that I have to encrypt the password using a Caesar Cypher, but I can figure that out later:

        encryptedPassword = passwordEncrypt(unencryptedPassword, encryptionKey)
        passwords.append(website, passwordEncrypt)
I am unsure what I am doing wrong, and where to go from here.
Quote
#2
I do this all the time, but usually with tuples. You can only append one item, but you want to append two. But note that passwords is a list of lists, each sub-list having two items. So you append one list with two items:

passwords.append([website, passwordEncrypt])
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote
#3
Quote:
encryptedPassword = passwordEncrypt(unencryptedPassword, encryptionKey)
passwords.append(website, passwordEncrypt)

Two things:
  1. You assign a value to variable encryptedPassword but you are using a variable named passwordEncrypt.
  2. You want to append a new list to the list "passwords", but you are adding the contents of two variables.
So use:
passwords.append([website, encryptedPassword])
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Search character from 2d list to 2d list AHK2019 3 102 Sep-25-2019, 08:14 PM
Last Post: ichabod801
  I donr know how to search from 2d list to 2d list AHK2019 1 85 Sep-25-2019, 01:59 AM
Last Post: ichabod801
  sort a list alphabeticaly without changing the original list Holmen 5 540 Jan-27-2019, 01:49 PM
Last Post: Holmen
  Dictionary/List Homework ImLearningPython 22 1,770 Dec-17-2018, 12:12 AM
Last Post: ImLearningPython
  making a dictionary from a list, one key with multiple values in a list within a list rhai 4 745 Oct-24-2018, 06:40 PM
Last Post: LeSchakal
  List of far points of two list antoniomancera 2 1,020 Nov-16-2017, 08:45 AM
Last Post: antoniomancera
  list of list to list of tuple? student8 2 969 Nov-14-2017, 08:06 AM
Last Post: buran

Forum Jump:


Users browsing this thread: 1 Guest(s)