Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6880961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:02:51+00:00 2026-05-27T05:02:51+00:00

Beginner programmer here. after a bunch of reading about ‘variables’ which dont exist in

  • 0

Beginner programmer here. after a bunch of reading about ‘variables’ which dont exist in python, (still dont get that) Ive come to the opinion that I think I should be using lists in my data structure, but im not entirely sure.

im analysing a string which contains commands and normal words to be printed out, if the word is a command, which in this case is preceded by an ‘@’ i want it to be in a separate list to the actual words. i will then process all this to be printed out afterwards, but i want the list to be ordered, so i can go through each element and test if it has a word in it, and if not do some action on the command.

so what i want really is a list with two indices(thankyou!) (what do you call that ?)
like this:

arglist[x][y]

so i can go through arglist and process whether or not it contains a command or a word to be printed out. i want arglist[x] to contain words and arglist[y] to contain commands.

arglist = [] # not sure how to initialise this properly.
doh="my @command string is this bunch of words @blah with some commands contained in it"
for listindex, word in enumerate(doh):
    if word.startswith('@'):
        # its a command 
        arglist[listindex] = None
        arglist[listindex][listindex]=command
    else:
        # its a normal word
        arglist[listindex]=word
        rglist[listindex][listindex]=None

then i want to be able to go down the list and pick out commands,
i guess that would be something like this:

# get the number of items in the list and go through them...
for listindex, woo in enumerate(len(arglist)):
    if arglist[listindex] is None:
        # there is no word here, so print command
        print arglist[listindex][listindex]      
        else:
            # just print out word
            print arglist[listindex] 

so: my question is which data type/ structure should I be using and should I / how do I initialise it ? am I barking up the right tree here?

edit: i just found this gem and now im even more unsure – i want it to be the fastest lookup possible on my data but i still want it to be ordered.

dict and set are fundamentally different from lists and tuples`. They store the hash of their keys, allowing you to see if an item is in them very quickly, but requires the key be hashable. You don’t get the same membership testing speed with linked lists or arrays.

many thanks as usual for any help.

edit: eg my string from above should look something like this.
doh=”my @command string is this bunch of words @blah with some commands contained in it”

arglist[1] = 'my'
arglist[1][1] = None

arglist[2] = None
arglist[2][1] = command

arglist[3] = 'string'
arglist[3][1] = None

etc etc

this whole thing has left me a bit baffled i shall try and update this later.

EDIT: if anyone wanted to know what this was all about look here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:02:52+00:00Added an answer on May 27, 2026 at 5:02 am

    The problem here is you’ve misunderstood the concept of multidimensional lists (arrays). To annotate the expected output you appended to your question:

    arglist[1] = 'my'
    arglist[1][1] # equivalent to 'my'[1], so you get 'y'.
                  # and you cannot assign anything to arglist[1][1] 
                  # because 'str' is immutable
    
    arglist[2] = None
    arglist[2][1] # invalid, because arglist[2] (None) is not subscriptable
    

    If you simply want to iterate through the words and perform different operations depending on whether it is a command (starts with @) or a word, then you can do:

    for val in doh.split():
        if val.startswith("@"):  # this is a command
            do_commandy_stuff(val)
        else:   # this is a word
            do_wordy_stuff(val)
    

    If what you want is to be able to quickly look up words using and index and determine if it is a command or not, then how about:

    >>> lookup = [(w.startswith("@"), w) for w in doh.split()]
    >>> lookup
    [(False, 'my'), (True, '@command'), (False, 'string'), (False, 'is'), (False, 'this'), (False, 'bunch'), (False, 'of'), (False, 'words'), (True, '@blah'), (False, 'with'), (False, 'some'), (False, 'commands'), (False, 'contained'), (False, 'in'), (False, 'it')]
    

    lookup is now a list of tuples. The first value in the tuple denotes if it is a command or not, the second stores the word.

    Looking words up is simple:

    is_command, word = lookup[1]   # is_command = True, word = "@command"
    

    While this seems closer to what you’re trying to achieve, I don’t see an obvious benefit unless you need lots of random access to words.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Beginner programmer here. So bear with me. I have a simple python program. print
I am a beginner programmer, using python on Mac. I created a function as
First of all, I am a beginner programmer (still much to learn). In one
I'm re-inventing the wheel here, but as I'm a beginner programmer I'm curious as
Im a beginner programmer, and my question is: Which image format shall i use
I'm a beginner programmer. Which one suites me better? I'm writing cross platform application.
I'm a young (highschool next year) beginner programmer, currently learning Python and starting to
I'm a beginner programmer and I'm learning my first language, C. I'm learning mostly
I'm a beginner programmer, and am wondering how to work around this issue. The
I'm a beginner C++ programmer, and to stretch my mind I've been trying some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.