Programming :: List Sorting In Python?

May 10, 2011

I have a list of list and I'd like to sort the list according to the last value of each row.

Let's say we have the list

L1 = [ [1,2] , [4,6] , [78,-3] ]

I wish to get

L2 = [ [78,-3] , [1,2] , [4,6] ]

Is there a simple way to do that in python?

View 4 Replies


ADVERTISEMENT

Programming :: Take A List From A File And Use It In A For Loop In Python?

May 11, 2009

so far I have this

list = open('list.txt')
for x in list:
list.read(x)

View 3 Replies View Related

Programming :: Python: List Running Audio Processes?

Jul 19, 2010

I am trying to get a list of running processes using audio (using gstreamer), just like in gnome-volume-control, under applications, but have so far been unsuccessful in finding anything in either the gtk or gstreamer library, anyone out there who can point me in the right direction?

View 1 Replies View Related

Programming :: Python: Dynamically Create A List Within A Dictionary?

Jul 9, 2011

how to dynamically create a list within a dictionary using Python.

Code:
dates = defaultdict(int)
array = []
...
dates[m.group(3)] = array.append(date)
dates[m.group(3)] = [array.append(date)]
dates[m.group(3)].append(date)

None of the above works and I've tried everything I can think of.

View 3 Replies View Related

Debian Programming :: Searching For A List Of Strings In File With Python

Oct 14, 2013

I'm trying to search for several strings, which I have in a .txt file line by line, on another file.

So the idea is, take input.txt and search for each line in that file in another file, let's call it rules.txt.

So far, I've been able to do this, to search for individual strings:

Code: Select allimport re

shakes = open("output.csv", "r")

for line in shakes:
    if re.match("STRING", line):
        print line,

How can I change this to input the strings to be searched from another file?

So far I haven't been able to.

View 3 Replies View Related

Debian Programming :: Return How Many Items Occurs In List (Python)

Jan 29, 2014

I going through the Python course on Codeacademy. I have some trouble understanding what I'm doing wrong. This is my code below:

Code: Select alldef count(sequence, item):
    total = 0
    for x in sequence:
        return x
        if x in sequence:
            total += 1
    return total
print count([1,2,1,1], 1 )

The code gives me an error: "Oops, try again. Your function fails on count([1],7). It returns 1 when it should return 0."

It should be outputting 3 because 1 occurs 3 times in the list.

View 7 Replies View Related

Programming :: Python Error - List Index Out Of Range (Web Scrapper)

Feb 18, 2011

Having a bit of an issue with Python while trying to write a script to download every rar file on a webpage. The script successfully downloads any link that doesn't contain any spaces, etc. But when it hits a url like: [URL] (Classical Spelling).rar. It fails...I'm sure this is something simple, but I'm so new to python I'm not sure what to do!

Code:
import urllib2
import os
os.system("curl [URL] -i rar|cut -d '"' -f 2 > temp.out ")
infile =open('temp.out', 'r')
for url in infile:
print url
#url = "[URL]"

#url = target
file_name = url.split('/')[-1]
u = urllib2.urlopen(url)
f = open(file_name, 'w')
meta = u.info()
file_size = int(meta.getheaders("Content-Length")[0])
print "Downloading: %s Bytes: %s" % (file_name, file_size)
file_size_dl = 0
block_sz = 8192

while True:
buffer = u.read(block_sz)
if not buffer:
break
file_size_dl += block_sz
f.write(buffer)
status = r"%10d [%3.2f%%]" % (file_size_dl, file_size_dl * 100. / file_size)
status = status + chr(8)*(len(status)+1)
print status,
f.close()

View 7 Replies View Related

Programming :: Make Python Programs Run Without Entering The Command Python?

Mar 22, 2009

I want to be able to do

sudo ./program.py

instead of always having to do

sudo python program.py

What do I need to change?

View 5 Replies View Related

Programming :: Python - Get Text File Data Into An Array On Python?

Nov 30, 2009

I've already used line split stuff to transform my data into something like this in a text file:

Code:

['1', '1', '3', '20.7505207']
['2', '1', '3', '23.0488319']
['3', '1', '3', '-1.5768747']
['4', '1', '3', '-26.4772491']

[code]....

How can I get this on a python program so I can manipulate it as an array?

View 3 Replies View Related

Programming :: Sorting 2 Dimension Array?

Aug 5, 2010

how to sort the 2 dimensional array below by column 1 then by column 2?

22 55
2222 2230
33 66
44 58
222 240

[Code].....

this is a small part in my awk script. the input data is not in file, but it was manipulated in my script.

View 6 Replies View Related

Programming :: Sorting A Dictionary File?

Nov 1, 2010

I have this dictionary file that has this format:

SUBSTITUTE_VALUE, Real Value
SUBSTITUTE_VALUE_2, Real Big Value
SUBSTITUTE_VALUE_HECL, Hardware Abstract
SUBSTITUTE_V, Valley Mem

I want to sort this file so the LONGEST Substitute Values are listed at the top ( so SUBSTITUTE_VALUE_HECL would be first in the list). Obviously I want to keep the related values tagging along with them, so the whole first line would be
SUBSTITUTE_VALUE_HECL, Hardware Abstract

Playing with sort This has me pretty close: sort dict.file -k1.1n,1

View 2 Replies View Related

Programming :: (PHP / XML) Sorting Through Multi Dimensional Array

Sep 17, 2010

I am parsing through XML documents with a PHP script and creating an array because, as far as I know, I can manipulate arrays better than the features DOM gives me. That part is not as important, though. The array it produces though is multi-dimensional, but somewhat inconsistent. If I have the following XML:

PHP Code:
<domains> <domain>
<title>google.com</title> <bookmarks>
<bookmark>maps.google.com</bookmark>
<bookmark>news.google.com</bookmark>
<bookmark>mail.google.com</bookmark>
</bookmarks> </domain> <domain>
<title>bankaccount.com</title>
<bookmarks> <bookmark>login.bankaccount.com</bookmark>
</bookmarks> </domain> </domains>

To call the first bookmark from the first domain, it would be:
PHP Code:
$array['domains']['domain'][0]['bookmarks']['bookmark'][0]
To call the first bookmark from the second domain, it would be:
PHP Code:
$array['domains']['domain'][1]['bookmarks']['bookmark']

The problem is, I want to simply call bookmarks through a simply 'foreach()' or 'for()' function and the lack of consistency might be a problem, but the fact that some levels have a '0' array key and others do not is causing a problem.

View 1 Replies View Related

Programming :: Reorganizing / Sorting Spreadsheet Using Shell?

Jun 25, 2011

I have a problem to reorganize a spreedsheat using shell, I want to use "sort" to organize the first column (descending scale) and then organize the second column in an ascending scale related to the first column so that the final result should be that one displayed at the end of the message. I have tried "sort -r -n" but I don't know how to reorganize the second column related to the first column.

40.0 20.0 9
40.0 15.0 8
40.0 10.0 14
40.0 5.0 12
39.0 15.0 18
39.0 10.0 19
39.0 20.0 5
39.0 5.0 4
41.0 20.0 10
41.0 15.0 12
41.0 5.0 8
41.0 10.0 7

Solution:
41.0 5.0 8
41.0 10.0 7
41.0 15.0 12
41.0 20.0 10
40.0 5.0 12
40.0 10.0 14
40.0 15.0 8
40.0 20.0 9
39.0 5.0 4
39.0 10.0 19
39.0 15.0 18
39.0 20.0 5

View 14 Replies View Related

Programming :: QListView - Way To Turn Off / Reverse Sorting?

Aug 23, 2010

QTreeView and QTableView have sort functions, but I need to sort a QListView, and for there to be no way for the user to turn off or reverse sorting.

View 11 Replies View Related

Programming :: Sorting Specific Values From An XML File

Sep 21, 2010

I need a shell script which gathers the data from a remote XML file and then displays it according to my needs.. I need this for my job due to the fact that I need to keep track price changes of euro, usd, gold, etc. The XML file I am talking about is located at this page: here. The reason I am posting the URL is that I need to use curl to get this file and it does NOT have newlines after each tag. I thought that that would be a problem. Here is what I need from the script: 1) curl to get the page 2) make use of sed, awk, etc. to display its contents in a more structured and readable manner as shown below:

A: 64.125 (% -0.26)
B: 81.130 (% -0.32)
C: 1.4930 (% 0.00)
D: 1.9590 (% 0.36)

View 5 Replies View Related

Programming :: PHP - Sorting Multi Dimensional Arrays By One Column

Mar 17, 2009

I just started programming in PHP so I haven't figured out how to do this yet, but I have a multi-dimensional array that I need to sort by one column. That's fine...but I need the sort to ignore case! Right now I have it sorted by 'name' (the other column is 'uid').

The problem is that by the default the sort is case-sensitive so the array looks like this:
Code:
Apple 4015
Banana 4011
Cherry 4045
avocado 4046

I want to be able to sort the the 'name' column in a case-insensitive manner so that the array actually looks like:
Code:
Apple 4015
avocado 4046
Banana 4011
Cherry 4045

How to accomplish this? Just FYI I'm not actually sorting the PLUs for fruits...but it was a simple example. I'm actually doing this for a Facebook application.

View 2 Replies View Related

Programming :: Python 2.x - Represent The Same In Python 3.x

Mar 4, 2010

I have a function definition in a Python 2.x script which take a tuple as one of its arguments, but 2to3 has no answers nor any of my searching on how to represent the same in Python 3.x

Code:

def blah(self, (string1, string2))

View 4 Replies View Related

General :: Python Script Using Tar From A List Returns Error: Has No Attribute 'startswith'

Apr 4, 2011

create a tar file from a list? My script returns the error: AttributeError: 'list' object has no attribute 'startswith' I want to create a compressed tar file containing the directory /usr/lib and the files in the list assigned to variable b.

code:

import tarfile
tar = tarfile.open("backup.gz", "w:gz")

[code]....

View 3 Replies View Related

Programming :: List 4 Names From Users List And Output Them To Fbusers In Numbered Ascending Order?

Feb 2, 2010

How would I list 4 users ID numbered 10, 11, 12 and 13 from my users list and output them to a file busers where their names are numbered by ascending order? How would I accomplish that on a one line command?

View 4 Replies View Related

Programming :: Downloading A List Of Files From A Remote Server Using A List?

Feb 10, 2009

I am trying to get this script to work. The purpose is to download a list of modules from the slax.org the list consist of a list of module numbers. What I am trying to do is Download the file or the file name corresponding to the number in the list.the list is comma delimited. this is what I have done so far and I am a stand still.

#!/bin/sh
# Wget script to retrieve modules from slax.org modules
#
# ----Begin of user defined values -----
# Path to wget

[code].....

View 7 Replies View Related

Programming :: Totem Python Plugin Programming: Any Signal For Video Mouse Click?

Feb 9, 2011

I want that I click with the mouse on the video, it paused.I notice that there is "BaconVideoWidget" which I guess is the video rendering widget but it don't have signal named "clicked":

Code:
vd = totem_object.get_video_widget()
vd.connect("clicked", vd.hide)

[code]....

View 3 Replies View Related

Programming :: Python 2.x Vs 3.x

Apr 21, 2010

I'm starting to learn python and I am wondering whether I should start with python 2.x or should I just start learning python 3.x?

View 2 Replies View Related

Programming :: Convert Map From Python 2.x To 3.x

Apr 6, 2010

I have an existing line of code from a P2 script that I cannot find a solution to converting to P3:

Code:
for i, x in map(None, list1, list2):
I have found the information about converting the simple case:
map(None,x) becomes list(x)

But my googling was unable to find a solution when more than one iterable exists.

View 2 Replies View Related

Programming :: How To Run Python Script From C

Jan 31, 2010

I have a python script I wrote a while ago and now I would like to call that script from inside C. I know how to do one command from C, but how would you execute an entire script from C, and passing arguments? Like:

Code:

int main(void)
{
python( myprogram(1 2 3) );
}

So I can pass arguments to my script.

View 3 Replies View Related

Programming :: Py_FindMethod In Python 3.1.1

Jan 19, 2010

what the equivalent function in Python 3.1.1 is for Python 2.6.4s:

Py_FindMethod

Be buggered if I can find anything in the doco to say what replaced it or what alternative code may need to be entered to replace it

View 1 Replies View Related

Programming :: Python With Web Development ?

Dec 17, 2010

I have decided to learn python as it seems to be powerful not just for web development (like php) but also a clean powerful language for other puposes.

Q: Can someone suggest a tutorial or book, on learning python (beginner to intermediate) which has as its focus for learning, web development?

In order of preference: 1. Comprehensive, 2. Online, 3. Free

View 2 Replies View Related

Programming :: Piping In Bash Using Python?

Dec 16, 2010

I have a bash script that I want to import in to Python, mainly just to see if I can or not. However in the script I do use some piping of commands into sed to trim it down to what I need. When I tried doing it with the os.system() call, it didn't work. The exact error is

sed: -e expression #1, char 16: unterminated `s' command

However the command that was run can be run in bash without an error. Is there a better/another way to do this? For reference the command is:

Code:

locate -n 1 wp-config.php | sed 's/wp-config.php/
/g' | sed '/wp-config.php/ d' | sed '/^$/ d'

View 3 Replies View Related

Programming :: Accessing Python Scripts Using Web?

Mar 17, 2011

I am using Centos. I have written some scipts in python that access my routers and fetch the configuration, etc. Now i was thinking of creating a web interface which i can access from my windows XP. I want it to have good look n feel :-),

View 7 Replies View Related

Programming :: C++ Or Python - Create 3D Animation ?

Jan 25, 2009

I want to create 3D animation and also make some big programs. Is python capable of that? or should I stick to C++?

View 3 Replies View Related

Programming :: Linking Options For Python?

Dec 11, 2010

I am trying to build an application that must link with python so as to load a python module during runtime.I have this makefile :

Code:
[alex@iskandhar src]$ cat Makefile
CFLAGS = -Wall -O3 -I ../../../SPOOLES.2.2 -DARCH="Linux" -DSPOOLES -DARPACK

[code]....

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved