473,804 Members | 3,029 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

RE: Random Problems

use songs.extend( asongs ) #append is for single item - where ever it mightbe.
>>l1 = range(5)
l2 = range(5,10)
l1
[0, 1, 2, 3, 4]
>>l2
[5, 6, 7, 8, 9]
>>l1.extend(l 2)
l1
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>
good luck.
Edwin

-----Original Message-----
From: py************* *************** *************** *******@python. org
[mailto:py****** *************** *************** **************@ python.org]
On Behalf Of Cousin Stanley
Sent: Wednesday, August 13, 2008 10:19 PM
To: py*********@pyt hon.org
Subject: Re: Random Problems

Well the othe day I was making a program to make a list
of all the songs in certian directorys but I got a problem,
only one of the directorys was added to the list.
....
Here's some code .... that illustrates yours ....

import glob

songs = glob.glob( '/path/to/somewhere/*.mp3' )

asongs = glob.glob( 'path/to/somewhere/else/*.mp3' )

songs.append( asongs )

# repeat a few times appending lists from other dirs
all goes well but pick awalys is from the first directory
but songs awalys includes all the files I want it to.
songs.append( asongs ) is appending the entire asongs list
as a single item to the end of the songs list, not adding
each individual song as an entry ....

For example ....
>>l1 = range( 0 , 5 )
l2 = range( 5 , 10 )
l3 = range( 11 , 15 )

l1
[0, 1, 2, 3, 4]
>>>
l2
[5, 6, 7, 8, 9]
>>>
l3
[11, 12, 13, 14]
>>>
l1.append( l2 )

l1
[0, 1, 2, 3, 4, [5, 6, 7, 8, 9]]
>>>
l1.append( l3 )

l1
[0, 1, 2, 3, 4, [5, 6, 7, 8, 9], [11, 12, 13, 14]]

So, if you have a lot of entries in the original songs list
you're only adding a few entries to it in the form of another
list and most likely you didn't run enough random.choice tests
to flush out a pick that turned out to be one of the entire
asong lists that you added ....

You might try something like the following
where each tune gets added individually to
the song pool .... un-tested ....
# -------------------------------------------------------------------

import random
import glob

base_dir = 'c:/Documents and Settings/Admin/My Documents'

list_subdirs = [
'LimeWire/Saved/*.mp3' ,
'Downloads/*/*.mp3' ,
'Downloads/*/*/*.mp3' ,
'Downloads/*/*/*/*.mp3 ]

song_pool = [ ]

for this_dir in list_subdirs :

list_songs = glob.glob( "'%s/%s'" % ( base_dir , this_dir )

if list_songs :

for this_song in list_songs :

song_pool.appen d( this_song )

npicks = 41

print

for n in range( npicks ) :

this_pick = random.choice( song_pool )

print ' ' , this_pick

# -------------------------------------------------------------------


--
Stanley C. Kitching
Human Being
Phoenix, Arizona

--
http://mail.python.org/mailman/listinfo/python-list
The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure. If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof. Thank you.
Aug 14 '08 #1
0 988

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
3269
by: Dr John Stockton | last post by:
Q1 : Given an array such as might have been generated by var A = is there a highly effective way of reducing it to - i.e. removing the undefineds and shifting the rest down? A.sort().slice(0,n) // would do it, but sorts; and the number
8
1907
by: jon morgan | last post by:
OK, I'm going to be brave. There is a bug in VS.Net 1.1 that causes random compiler errors. I have raised this issue in posts at least three time in the past couple of months without attracting much interest. But it's driving me nuts. Here's what happens. I'm working on a multi project VB app. happily writing nice inoffensive code - go to compile and the compiler tells me there's a problem in a project I'm not working on. But really...
10
2911
by: Sonoman | last post by:
Hi all: I am trying to write a simple program that simulates asking several persons their birth day and it counts how many persons are asked until two have the same birth day. The problem that I have is that the first loop I get a sequence of random numbers untuil I get a match, BUT then on the following loops I get the SAME random(?) sequence. I am using rand(). I do not want to get too fancy with the random number generator, but is there...
9
3856
by: greeningster | last post by:
I have written an application in Visual C++ for a customer but it seems to crash randomly. Could anyone give me any help on how I could track this down ? Also, there appears there might be memory leaks too. How can i track these down ?
6
4692
by: Starbuck | last post by:
Hi In VB6 we used the following to create a unique random number - Function longSerial() As Long longSerial = Val((Format$(Int(Rnd * 424) - 212)) + Format$((Timer * 100), "0000000")) longSerial = longSerial Xor Int(2147483647 * Rnd)
13
3622
by: Roy Gourgi | last post by:
Hi, How do I invoke the random number generator that was suggested by a few people. Ideally, what I would like to do is to instantiate the random no. generator with a seed value that does not repeat the values and that can be called from any class, as I have to call the random number generator from a few different classes. Here is my code: using System;
5
3355
by: Peteroid | last post by:
I know how to use rand() to generate random POSITIVE-INTEGER numbers. But, I'd like to generate a random DOUBLE number in the range of 0.0 to 1.0 with resolution of a double (i.e., every possible double value in the range could come up with equal probability). I'd also like to be able to seed this generator (e.g., via the clock) so that the same sequence of random values don't come up every time. Anybody have an easy and fast...
2
1814
by: blaine | last post by:
Hey everyone, Just a friendly question about an efficient way to do this. I have a graph with nodes and edges (networkx is am amazing library, check it out!). I also have a lookup table with weights of each edge. So: weights = .12 weights = .53 weights = 1.23 weights = -2.34 etc.
20
2304
by: Robbie Hatley | last post by:
I needed a quick program called "random" that gives a random positive integer from n1 to n2. For example, if I type "random 38, 43", I want the program to print a random member of the set {38, 39, 40, 41, 42, 43}. Also, I read in my compiler's documentation the following: To get a random number in the range 0..N, use rand()%(N+1). Note that the low bits of the rand's return value are not very random, so rand()%N for small values of N...
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10326
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10317
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9143
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6851
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4295
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.