Python: manipulating lists


her209
7/5/2016 5:43 am
HOME ยป Web Development

problem

I have to get elements from a text file to a list, diagonally and from top to buttom. Any help would be appreciated. the file would look like this:

text file: letters.txt (thought it would be hard, i removed 'Y' and 'Z' from my first post

A B C D E F
G H I J K L
M N O P Q R 
S T U V W X

the lists should look like this:

topButtom_List = ['AGMS', 'BHNT', 'CIOU', 'DJPV', 'EKQW',
'FLRX']

bLeftToURight = ['A', 'GB', 'MHC', 'SNID', 'TOJE', 'UPKF', 'VQL',
'WR', 'X']

my current code for top to buttom:

# top to buttom
topButtom_List = [] #should be ['AGMS', 'BHNT', 'CIOU', 'DJPV',
'EKQW', 'FLRX']

openFile = open("letters.txt")
for i in openFile:
    i = i.replace(" ","")
length = len(i)
openFile.close()

openFile = open("letters.txt")   
counter = 0   
for eachIterration in range(length):
    for line in openFile:
        line = line.replace(" ","")
        # counter should be added by 1 each time inner loop itterates
x4, and outter loop x1.
        topButtom_List.append(line[counter]) 
    counter = counter + 1
openFile.close()

What I was trying to do with the code above:

I was trying to get the top to buttom characters from the text file and get it in a list called topButtom_List. I used counter to define the index that for every itteration the outer loop does, the index would be added by 1. The way I see it is, the outerloop will start, the inner loop will itterate x4 adding AGMS in the topButtom_List on the first itteration, the outer loop will itterate again and add 1 to counter. BHNTZ will be added on the second itteration and so on, the outer loop will itterate again and add 1 to counter.

from the text file: letters.txt I want to populate topButtom_List

output I am getting:

['A', 'G', 'M', 'S']

expected output:

['AGMS', 'BHNT', 'CIOU', 'DJPV', 'EKQW', 'FLRX']

Related to : Python: manipulating lists
Python: manipulating lists
7/5/2016 5:43 am by her209 in Web Development

problem

I have to get elements from a text file to a list, diagonally and from top to buttom. Any help would be appreciated. the file would look like this:

text file: letters.txt (thought it would be hard, i removed 'Y' and 'Z' from my first post<


Python - manipulating lists to create another list
by GregoryWE in Web Development

I have a number of lists that are of equal length, say 4, but this can change. What I want to do is combine these lists, so that the first item of each list, item[0], is combined to form a new list. Similarly with item[1], item[2] etc. This seems simple enough, but how do I make sure that the lis


Recursively remove spaces in a list (of lists of lists of lists…) in python
by JoeKaras in Web Development

I'm trying to remove all of the spaces from elements in a list of lists (potentially of lists of lists etc. etc.)


The module I've written returns the first appearance of a base case alone instead of the whole recursed object, if that makes sense. Any idea what I've done wrong?


TAGS: Recursively remove spaces list lists lists
How do I convert a nested tuple of tuples and lists to lists of lists in Python?
by AJacques in Web Development

I have a tuple containing lists and more tuples. I need to convert it to nested lists with the same structure. For example, I want to convert (1,2,[3,(4,5)]) to [1,2,[3,[4,5]]].


How do I do this (in Python)?


“Slice lists” and “the ellipsis” in Python; slicing lists and lists of lists with lists of slices
by seventy6 in Web Development

Original question: Can someone tell me how to use "slice lists" and the "ellipsis"? When are they useful? Thanks.


Here's what the language definition says about "slice_list" and "ellipsis"; Alex Martelli's answer points out their origin, which is not what I had envisioned.


TAGS: ldquo Slice lists rdquo ldquo ellipsis
Manipulating lists
by cpacini in Web Development

Hey.
I have a file which reads something like this:
19001 ACTGTGGRA 0.452
19002 CATTAGTTC 0.900
. ... ..
. ... ..
I want to write a script which deletes the opening numbers (19001 etc) and only pr
manipulating lists :
by diablo805 in Web Development

I have written a code to manipulate the contents of a time series data and output into a newly created matrix. This is to enable me construct the phase space for the time series data.


The list is one-dimensional of length=N called "noise".


I want to create a MxN matrix whe


Manipulating lists :(
by Pakistan in Web Development

Hi ,,I am having trouble getting used to Python so I decided to ask a question here.
What i need is for a function or a list to hold the results of the loop in a list,,as you see inthis one,, say x[1:5],,would be the same after the loop.
Sorry about the stupid question ,,any ti
Ocaml manipulating lists
by Rhoxed in Web Development

real basic question here: I'm new to Ocaml and I'm having issues trying to manipulate lists. I've read http://caml.inria.fr/pub/docs/manual-ocaml/libref/List.html, and I'm unfortunately still confused....I'm new to functional programming.


If I have, say, the following function:

TAGS: Ocaml manipulating lists
manipulating unnumbered lists
by kodeninja in Web Development
Im using AJAX to send a request to a PHP page for a list of pages in a database, the PHP scripts returns the list in XML format.
Im going to parse the XML and generate an array.
Is it possible to have javascript/ajax manipulate an unnumbered list and create a list item for each item in the
Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2014 © bighow.org All Rights Reserved .