How to change the number into the same expression's string and vice versa?
In the python3 console: >>> a=18 >>> b='18' >>> str(a) == b True >>> int(b) == a True Now how to change a1,a2,a3 into b1,b2,b3 and vice versa? a1=0xf4 a2=0o36 a3=011 b1='0xf4' b2='0o36' b3='011' -- https://mail.python.org/mailman/listinfo/python-list
Re: How to change the number into the same expression's string and vice versa?
contro opinion wrote:
> In the python3 console:
>
> >>> a=18
> >>> b='18'
> >>> str(a) == b
> True
> >>> int(b) == a
> True
>
>
> Now how to change a1,a2,a3 into b1,b2,b3 and vice versa?
> a1=0xf4
> a2=0o36
> a3=011
>
> b1='0xf4'
> b2='0o36'
> b3='011'
Python 3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> "{:o}".format(0xf4)
'364'
>>> "{:x}".format(0xf4)
'f4'
>>> "{}".format(0xf4)
'244'
To add a prefix just put it into the format string.
You can specify the base for int() or trigger automatic base recognition by
passing a base of 0:
>>> int("f4", 16)
244
>>> int("0xf4", 0)
244
>>> int("0o36", 0)
30
The classical prefix for base-8 numbers is no longer recognised in Python 3:
>>> int("011", 0)
Traceback (most recent call last):
File "", line 1, in
ValueError: invalid literal for int() with base 0: '011'
>>> int("011")
11
>>> int("011", 8)
9
--
https://mail.python.org/mailman/listinfo/python-list
Re: How to change the number into the same expression's string and vice versa?
"contro opinion" wrote in message
news:ca+ydq_651x0ndpw1j203wgbedtxy_mw7g0w3vh1woagr1iv...@mail.gmail.com...
> In the python3 console:
>
>>>> a=18
>>>> b='18'
>>>> str(a) == b
>True
>>>> int(b) == a
>True
>
>
> Now how to change a1,a2,a3 into b1,b2,b3 and vice versa?
> a1=0xf4
> a2=0o36
> a3=011
>
> b1='0xf4'
> b2='0o36'
> b3='011'
>
I am no expert, but does this answer your question ?
C:\>python
Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> a1 = 0xf4
>>> a1
244
>>> b1 = '0x{:x}'.format(a1)
>>> b1
'0xf4'
>>> int(b1, 16)
244
>>> a2 = 0o36
>>> a2
30
>>> b2 = '0o{:o}'.format(a2)
>>> b2
'0o36'
>>> int(b2, 8)
30
>>> a3 = 011
File "", line 1
a3 = 011
^
SyntaxError: invalid token
>>>
Frank Millman
--
https://mail.python.org/mailman/listinfo/python-list
Re: How to change the number into the same expression's string and vice versa?
Peter Otten writes:
> contro opinion wrote:
> > Now how to change a1,a2,a3 into b1,b2,b3 and vice versa?
> > a1=0xf4
> > a2=0o36
> > a3=011
> >
> > b1='0xf4'
> > b2='0o36'
> > b3='011'
>
> Python 3.4.0 (default, Apr 11 2014, 13:05:11)
> [GCC 4.8.2] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> "{:o}".format(0xf4)
> '364'
> >>> "{:x}".format(0xf4)
> 'f4'
> >>> "{}".format(0xf4)
> '244'
>
> To add a prefix just put it into the format string.
There's also these (in Python 3.2.3):
>>> hex(0xf4)
'0xf4'
>>> oct(0xf4)
'0o364'
>>> bin(0xf4)
'0b0100'
--
https://mail.python.org/mailman/listinfo/python-list
Storing dataset from Condtional FreqDist
Hello i have trying to store information in arff file but i has been really.
Any ideas of how can i do that?
with open('fileids3.txt', 'r') as f:
genres=[word.strip() for word in f.next().split(',')]
with open('adjectifs2.txt', 'r') as g:
adj = [word.strip() for word in g.next().split(',')]
freq = nltk.ConditionalFreqDist(
(genre, m)
for genre in brown.fileids()
for m in brown.words(fileids=genre))
freq.tabulate(conditions=genres, samples=adj)
--
https://mail.python.org/mailman/listinfo/python-list
ANN: eGenix Talks & Videos: Advanced Database Programming
ANNOUNCING eGenix Talks & Videos "Advanced Database Programming" This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/EuroPython-2014-Advanced-Database-Programming.html eGenix Talk "Advanced Database Programming" At last year's EuroPython 2014 conference in Berlin, Marc-André Lemburg, CEO of eGenix, gave the following talk on database programming in Python. We have now turned the talk into video presentation for easy viewing and also released the presentation slides: EuroPython 2014 - Advanced Database Programming --- Advanced concepts in Python database programming. The Python DB-API 2.0 provides a direct interface to many popular database backends. It makes interaction with relational database very straight forward and allows tapping into the full set of features these databases provide. This talk covers advanced database topics which are relevant in production environments such as locks, distributed transactions and transaction isolation. We also give advice on how to deal with common problems you face when working with complex database systems. http://www.egenix.com/library/presentations/EuroPython-2014-Advanced-Database-Programming/ Related Python Coaching and Consulting -- If you are interested in learning more about these advanced techniques, eGenix now offers Python project coaching and consulting services to give your project teams advice on how to implement complex database architectures in Python. Please contact our eGenix Sales Team ([email protected]) for information. http://www.egenix.com/services/coaching/ More interesting eGenix presentations are available in the presentations and talks section of the library on our website: http://www.egenix.com/library/presentations/ Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 19 2015) >>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ >>> mxODBC Plone/Zope Database Adapter ... http://zope.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/ 2015-01-09: Released eGenix pyOpenSSL 0.13.7 ... http://egenix.com/go68 2015-01-20: Python Meeting Duesseldorf ...http://egenix.com/go69 : Try our mxODBC.Connect Python Database Interface for free ! :: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ -- https://mail.python.org/mailman/listinfo/python-list
Re: How to change the number into the same expression's string and vice versa?
Jussi Piitulainen wrote:
> Peter Otten writes:
>> >>> "{:o}".format(0xf4)
>> '364'
>> To add a prefix just put it into the format string.
> There's also these (in Python 3.2.3):
>
> >>> hex(0xf4)
> '0xf4'
D'oh!
--
https://mail.python.org/mailman/listinfo/python-list
Re: How to "wow" someone new to Python
On 1/16/15 10:03 AM, Chris Angelico wrote: Scenario: You're introducing someone to Python for the first time. S/he may have some previous programming experience, or may be new to the whole idea of giving a computer instructions. You have a couple of minutes to show off how awesome Python is. What do you do? I was thinking along the lines of a simple demo in the REPL, showing off some of Python's coolest features. But then I got stuck on the specifics. What are Python's best coolnesses? What makes for a good demo? Ideally, this should be something that can be demo'd quickly and easily, and it should be impressive without going into great details of "and see, this is how it works on the inside". So, how would you brag about this language? ChrisA Peter Norvig's spell corrector is a compact example of a lot of Python power: http://norvig.com/spell-correct.html I used it as a walk-through example for a presentation about Python at the DevDays conference: http://nedbatchelder.com/text/devdays.html The second half of the presentation is a 25-line nano-templating engine which shows off some other good characteristics of the language. -- Ned Batchelder, http://nedbatchelder.com -- https://mail.python.org/mailman/listinfo/python-list
Hashed lookups for tabular data
I have some tabular data for example 3 tuples that I need to build a container for where lookups into any one of the three fields are O(1). Does something in the base library exist, or if not is there an efficient implementation of such a container that has been implemented before I give it a go? It complicates slightly by the fact that for the some of the collections, one of the fields may be duplicated, think (make, model, year) for example which closely resembles the pattern of one the data sets. When asking for position 0 of the set, I'd expect to get an iterable of length "n" but some of the containers will be inherently unique for the rows that will be accessed so I'd return a single row. No surprise the data originates from a database however the data is utilized in a recursive processing loop where the user accessing the data benefits from a simplified and quick means to access it. Currently its done with classes that resemble named tuples equating to a row, but it goes pear shaped with the outer container. Grouping these similar objects and providing the sql like query into the collection in some cases is O(n)... Thanks, jlc -- https://mail.python.org/mailman/listinfo/python-list
Re: Hashed lookups for tabular data
On Tue, Jan 20, 2015 at 1:13 AM, Joseph L. Casale
wrote:
> No surprise the data originates from a database however the data is utilized
> in
> a recursive processing loop where the user accessing the data benefits from a
> simplified and quick means to access it. Currently its done with classes that
> resemble named tuples equating to a row, but it goes pear shaped with the
> outer
> container. Grouping these similar objects and providing the sql like query
> into
> the collection in some cases is O(n)...
So presumably your data's small enough to fit into memory, right? If
it isn't, going back to the database every time would be the best
option. But if it is, can you simply keep three dictionaries in sync?
row = (foo, bar, quux) # there could be duplicate quuxes but not foos or bars
foo_dict = {}
bar_dict = {}
quux_dict = collections.defaultdict(set)
foo_dict[row[0]] = row
bar_dict[row[1]] = row
quux_dict[row[2]].add(row)
You can now look up anything by any key. If you use the quux_dict,
you'll get back a list (zero elements if you've never seen one,
otherwise all elements ever seen, in arbitrary order). Adding, in this
way, is idempotent.
Finding an item by foo or bar is easy - use either of:
row = foo_dict["asdf"] # will raise KeyError if it isn't there
row = foo_dict.get("qwer") # will return None if it isn't there
Finding items by quux is a matter of iteration:
for row in quux_dict["zxcv"]:
do something
It's up to you to decide whether it's an error to get back an empty set or not.
Does this give a basic idea of what you can do?
The memory requirements wouldn't be much more than your existing data.
You have three lookup dictionaries, but the actual keys and values
would be shared. The main consideration is that you'd need to update
in lots of places if you remove a row. If you're working with stable
data across one run of the program, though, that should be safe.
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
Re: How to change the number into the same expression's string and vice versa?
On 19/01/2015 09:01, contro opinion wrote: In the python3 console: >>> a=18 >>> b='18' >>> str(a) == b True >>> int(b) == a True Now how to change a1,a2,a3 into b1,b2,b3 and vice versa? a1=0xf4 a2=0o36 a3=011 b1='0xf4' b2='0o36' b3='011' Giving a completely different take on previous answers how about. a1, b1 = b1, a1 a2, b2 = b2, a2 a3, b3 = b3, a3 -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Hashed lookups for tabular data
> So presumably your data's small enough to fit into memory, right? If
> it isn't, going back to the database every time would be the best
> option. But if it is, can you simply keep three dictionaries in sync?
Hi Chris,
Yeah the data can fit in memory and hence the desire to avoid a trip here.
> row = (foo, bar, quux) # there could be duplicate quuxes but not foos or bars
> foo_dict = {}
> bar_dict = {}
> quux_dict = collections.defaultdict(set)
>
> foo_dict[row[0]] = row
> bar_dict[row[1]] = row
> quux_dict[row[2]].add(row)
This is actually far simpler than I had started imagining, however the row data
is duplicated. I am hacking away at an attempt with references to one copy of
the row.
Its kind of hard to recreate an sql like object in Python with indexes and the
inherent programmability against a single copy of data.
I'll mock this up and see what it profiles like.
Thanks!
jlc
--
https://mail.python.org/mailman/listinfo/python-list
Re: Hashed lookups for tabular data
On Tue, Jan 20, 2015 at 4:09 AM, Joseph L. Casale
wrote:
>> row = (foo, bar, quux) # there could be duplicate quuxes but not foos or bars
>> foo_dict = {}
>> bar_dict = {}
>> quux_dict = collections.defaultdict(set)
>>
>> foo_dict[row[0]] = row
>> bar_dict[row[1]] = row
>> quux_dict[row[2]].add(row)
>
> This is actually far simpler than I had started imagining, however the row
> data
> is duplicated. I am hacking away at an attempt with references to one copy of
> the row.
As long as you start with an actual tuple that you then assign in that
way, they will all be references to one copy of the row. Here's a
concrete example:
$ python3
Python 3.5.0a0 (default:1c51f1650c42+, Dec 29 2014, 02:29:06)
[GCC 4.7.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> row = ("abc","def","ghi")
>>> foo_dict = {}
>>> bar_dict = {}
>>> import collections
>>> quux_dict = collections.defaultdict(set)
>>> foo_dict[row[0]] = row
>>> bar_dict[row[1]] = row
>>> quux_dict[row[2]].add(row)
>>> id(foo_dict["abc"])
140127396717840
>>> id(bar_dict["def"])
140127396717840
>>> id(next(iter(quux_dict["ghi"])))
140127396717840
The IDs of the objects prove that they're actually all the same
object. The memory requirement for this is just what the dictionaries
themselves require; their keys and values are all shared with other
usage.
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
Re: Hashed lookups for tabular data
On 19/01/2015 17:09, Joseph L. Casale wrote: This is actually far simpler than I had started imagining, however the row data is duplicated. I am hacking away at an attempt with references to one copy of the row. Its kind of hard to recreate an sql like object in Python with indexes and the inherent programmability against a single copy of data. I'll mock this up and see what it profiles like. Thanks! jlc Why not take a look at pandas as see if there's anything there you could use? Excellent docs here http://pandas.pydata.org/pandas-docs/stable/ and the mailing list is available at gmane.comp.python.pydata amongst other places. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Hashed lookups for tabular data
"Joseph L. Casale" writes:
>> So presumably your data's small enough to fit into memory, right? If
>> it isn't, going back to the database every time would be the best
>> option. But if it is, can you simply keep three dictionaries in sync?
>
> Hi Chris,
> Yeah the data can fit in memory and hence the desire to avoid a trip here.
>
>> row = (foo, bar, quux) # there could be duplicate quuxes but not foos or bars
>> foo_dict = {}
>> bar_dict = {}
>> quux_dict = collections.defaultdict(set)
>>
>> foo_dict[row[0]] = row
>> bar_dict[row[1]] = row
>> quux_dict[row[2]].add(row)
>
> This is actually far simpler than I had started imagining, however the row
> data
> is duplicated. I am hacking away at an attempt with references to one copy of
> the row.
>
> Its kind of hard to recreate an sql like object in Python with indexes and the
> inherent programmability against a single copy of data.
>
If you want an sql-like interface, you can simply create an in-memory
sqlite3 database.
import sqlite3
db = sqlite3.Connection(':memory:')
You can create indexes as you need, and query using SQL. Later, if you
find the data getting too big to fit in memory, you can switch to using
an on-disk database instead without significant changes to the code.
--
regards,
kushal
--
https://mail.python.org/mailman/listinfo/python-list
Re: Hashed lookups for tabular data
> The IDs of the objects prove that they're actually all the same > object. The memory requirement for this is just what the dictionaries > themselves require; their keys and values are all shared with other > usage. Chris, I would have never imagined that, much appreciated for that! jlc -- https://mail.python.org/mailman/listinfo/python-list
Re: Hashed lookups for tabular data
> Why not take a look at pandas as see if there's anything there you could > use? Excellent docs here http://pandas.pydata.org/pandas-docs/stable/ > and the mailing list is available at gmane.comp.python.pydata amongst > other places. Mark, Actually it was the first thing that came to mind. I did want to avoid another dependency unless it was for a good reason and I suspect anything from that project would merit it one. I have been looking for a reason to use it for a project and this might be it. I probably wont be up to speed in time but I will give it a look. Thanks, jlc -- https://mail.python.org/mailman/listinfo/python-list
Re: Hashed lookups for tabular data
> If you want an sql-like interface, you can simply create an in-memory
> sqlite3 database.
>
> import sqlite3
> db = sqlite3.Connection(':memory:')
>
> You can create indexes as you need, and query using SQL. Later, if you
> find the data getting too big to fit in memory, you can switch to using
> an on-disk database instead without significant changes to the code.
Hey kushal,
For the effort it would take, I'll add an implementation using this this
when I start profiling for the sake of curiosity.
Thanks,
jlc
--
https://mail.python.org/mailman/listinfo/python-list
Trees
Why aren't there trees in the python standard library? -- https://mail.python.org/mailman/listinfo/python-list
Re: Trees
Zachary Gilmartin writes: > Why aren't there trees in the python standard library? What sort of answer are you looking for? There are many ways that question could be intended. If you're asking about what could be keeping a particular tree implementation out of the standard library: that depends on what particular implementations you have in mind. Are there any which exist that you think belong in the standard library? If you're asking about some policy that prevents any such inclusion, I'm not aware of such a policy. If you're asking because you think all data structures magically appear in the standard library by wishing it so, I think you over-estimate the powers of the standard library maintainers. If you're asking something else, you'll need to be more explicit. -- \“Every sentence I utter must be understood not as an | `\ affirmation, but as a question.” —Niels Bohr | _o__) | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: Trees
On Tue, Jan 20, 2015 at 9:16 AM, Ben Finney wrote: > If you're asking because you think all data structures magically appear > in the standard library by wishing it so, I think you over-estimate the > powers of the standard library maintainers. Oh come on Ben. Guido has a time machine; TimSort is pure magic coalesced into code form; and there's an army of buildbots standing by for every change that gets made. How can anyone over-estimate the powers of python-dev?! ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Trees
On 19/01/2015 22:06, Zachary Gilmartin wrote: Why aren't there trees in the python standard library? Probably because you'd never get agreement as to which specific tree and which specific implementation was the most suitable for inclusion. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Trees
Zachary Gilmartin wrote: > Why aren't there trees in the python standard library? Possibly because they aren't needed? Under what circumstances would you use a tree instead of a list or a dict or combination of both? That's not a rhetorical question. I am genuinely curious, what task do you have that you think must be solved by a tree? Also, what sort of tree? Binary tree? Binary search tree? Red/black tree? AVL tree? Splay tree? B-tree? T-tree? Scapegoat tree? General n-ary tree? Every possible type of tree yet invented? -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Trees
On 01/19/2015 04:08 PM, Steven D'Aprano wrote: > Zachary Gilmartin wrote: > >> Why aren't there trees in the python standard library? > > Possibly because they aren't needed? Under what circumstances would you use > a tree instead of a list or a dict or combination of both? > > That's not a rhetorical question. I am genuinely curious, what task do you > have that you think must be solved by a tree? > > Also, what sort of tree? Binary tree? Binary search tree? Red/black tree? > AVL tree? Splay tree? B-tree? T-tree? Scapegoat tree? General n-ary tree? > Every possible type of tree yet invented? Don't forget left-child,right-sibling trees. As I go through your list of trees, I can't find any tree type that cannot be easily and efficiently constructed with lists, possibly with dicts. -- https://mail.python.org/mailman/listinfo/python-list
Re: Trees
On Mon, Jan 19, 2015 at 3:08 PM, Steven D'Aprano wrote: > Zachary Gilmartin wrote: > >> Why aren't there trees in the python standard library? > > Possibly because they aren't needed? Under what circumstances would you use > a tree instead of a list or a dict or combination of both? > > That's not a rhetorical question. I am genuinely curious, what task do you > have that you think must be solved by a tree? In general, any time you want to maintain a sorted list or mapping, balanced search tree structures come in handy. Here's an example task: suppose you want to represent a calendar, where timeslots can be reserved for something. Calendar events are not allowed to intersect. The most important query is: What events are there that intersect with the timespan between datetimes d1 and d2? (To draw a daily agenda, figure out if you should display an alert to the user that an event is ongoing or imminent, etc.) You also want to be able to add a new event to the calendar, that takes place between d1 and d2, and to remove a event. I leave it to the reader to implement this using a sorted map. (hint: sort by start.) This maybe seems contrived, but I've used this exact datatype, or a remarkably similar one, in a few different circumstances: sequenced actions of characters in a strategy game, animation, motion planning... There are a few possible implementations using Python data structures. You can do it using a linear scan, which gets a little slow pretty quickly. You can make insertion slow (usually OK) by sorting on insertion, but if you ever forget to resort your list you will get a subtle bug you might not notice for a while. And so on. It's better in every way to use the third-party blist module, so why bother? -- Devin -- https://mail.python.org/mailman/listinfo/python-list
Re: Trees
On 2015-01-19 16:19, Michael Torrie wrote: > On 01/19/2015 04:08 PM, Steven D'Aprano wrote: > > Zachary Gilmartin wrote: > >> Why aren't there trees in the python standard library? > > > > Possibly because they aren't needed? Under what circumstances > > would you use a tree instead of a list or a dict or combination > > of both? While not an abundance of times, I've had a plurality of occasions when I've wanted characteristics of a red/black tree where I wanted O(log n) insertion/deletion/initial-access and O(1) access to neighbors. > > Also, what sort of tree? Binary tree? Binary search tree? > > Red/black tree? AVL tree? Splay tree? B-tree? T-tree? Scapegoat > > tree? General n-ary tree? Every possible type of tree yet > > invented? > > Don't forget left-child,right-sibling trees. > > As I go through your list of trees, I can't find any tree type that > cannot be easily and efficiently constructed with lists, possibly > with dicts. While the data-structures can easily be composed out of lists/dicts, the algorithms that go along with them (such as red/black trees with their insertion/deletion gymnastics) would be nice to have in the stdlib so they wouldn't have to be reimplemented (or sought out and downloaded, and added to the configuration/distribution) every time someone wanted that particular tree's characteristics. Much of that could be addressed with a library of algorithms much like heapq operates on a list. -tkc -- https://mail.python.org/mailman/listinfo/python-list
Concerning Dictionaries and += in Python 2.x
I have been having a bit of trouble with the things mentioned in the title. I
have written the following script for a Codecademy course:
stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
}
prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
}
def compute_bill(food):
total = 0
for item in food:
if stock[item] > 0:
total += prices[item]
stock[item] = stock[item] - 1
return total
Whenever I run this script, "4" is returned. It does not seem to matter what in
in the list the script is run on. I have tried this on the Codecademy
interpreter/emulator (I'm not sure which they use) and the repl.it interpreter,
but for the same result. If anyone could find the glitch in my code, please let
me know. Thanks!
--
https://mail.python.org/mailman/listinfo/python-list
Random ALL CAPS posts on this group
Has anyone noticed these? There have been about three of them recently and they don't seem to have anything to do with Python at all. Does anyone know if there is a good reason they are here? -- https://mail.python.org/mailman/listinfo/python-list
Re: Concerning Dictionaries and += in Python 2.x
On Tue, Jan 20, 2015 at 11:12 AM, Luke Tomaneng wrote: > def compute_bill(food): > total = 0 > for item in food: > if stock[item] > 0: > total += prices[item] > stock[item] = stock[item] - 1 > return total > Whenever I run this script, "4" is returned. It does not seem to matter what > in in the list the script is run on. I have tried this on the Codecademy > interpreter/emulator (I'm not sure which they use) and the repl.it > interpreter, but for the same result. If anyone could find the glitch in my > code, please let me know. Thanks! > In Python, indentation determines block structure. Have another look at this function, and see if you can figure out where the problem is; hint: try printing something out every time you claim a piece of stock. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Random ALL CAPS posts on this group
On Tue, Jan 20, 2015 at 11:15 AM, Luke Tomaneng wrote: > Has anyone noticed these? There have been about three of them recently and > they don't seem to have anything to do with Python at all. Does anyone know > if there is a good reason they are here? > I haven't seen them. My guess is they're straight-up spam; just ignore them, or mark them as spam if your client supports it. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Concerning Dictionaries and += in Python 2.x
On 2015-01-20 00:12, Luke Tomaneng wrote:
I have been having a bit of trouble with the things mentioned in the title. I
have written the following script for a Codecademy course:
stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
}
prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
}
def compute_bill(food):
total = 0
for item in food:
if stock[item] > 0:
total += prices[item]
stock[item] = stock[item] - 1
return total
Whenever I run this script, "4" is returned. It does not seem to matter what in
in the list the script is run on. I have tried this on the Codecademy
interpreter/emulator (I'm not sure which they use) and the repl.it interpreter, but for
the same result. If anyone could find the glitch in my code, please let me know. Thanks!
Work through it a step at a time.
You haven't said what 'food' is when 'compute_bill is called, but I'm
guessing that the first item it checks is "banana".
stock["banana"] == 6, so it adds prices["banana"] to total, subtracts 1
from stock["banana"], and then returns the total, 4, because that's
what you've told it to do.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Random ALL CAPS posts on this group
On Tuesday, January 20, 2015 at 5:52:54 AM UTC+5:30, Chris Angelico wrote: > On Tue, Jan 20, 2015 at 11:15 AM, Luke Tomaneng wrote: > > Has anyone noticed these? There have been about three of them recently and > > they don't seem to have anything to do with Python at all. Does anyone know > > if there is a good reason they are here? > > > > I haven't seen them. My guess is they're straight-up spam; just ignore > them, or mark them as spam if your client supports it. > > ChrisA In google groups you can mark spam by clicking the tiny downward triangle next to the Reply-arrow -> "Report abuse" -> spam -- https://mail.python.org/mailman/listinfo/python-list
Re: Concerning Dictionaries and += in Python 2.x
On Monday, January 19, 2015 at 4:21:58 PM UTC-8, Chris Angelico wrote: > On Tue, Jan 20, 2015 at 11:12 AM, Luke Tomaneng wrote: > > def compute_bill(food): > > total = 0 > > for item in food: > > if stock[item] > 0: > > total += prices[item] > > stock[item] = stock[item] - 1 > > return total > > Whenever I run this script, "4" is returned. It does not seem to matter > > what in in the list the script is run on. I have tried this on the > > Codecademy interpreter/emulator (I'm not sure which they use) and the > > repl.it interpreter, but for the same result. If anyone could find the > > glitch in my code, please let me know. Thanks! > > > > In Python, indentation determines block structure. Have another look > at this function, and see if you can figure out where the problem is; > hint: try printing something out every time you claim a piece of > stock. > > ChrisA Hm. I fixed the indentation like you said, and it worked fine. The only reason I changed the indentation to what you saw in the first place is because Codecademy's Python engine registered an error. However, repl.it accepted the script. I have concluded that the original mistake was actually on the Codecademy site instead of my script. Thanks for helping me out. -- https://mail.python.org/mailman/listinfo/python-list
Re: Concerning Dictionaries and += in Python 2.x
Thanks Chris / Mr. Angelico / whatever you prefer. I attempted to post a reply to you before but it could not be viewed even after refreshing several times. You've been helpful. -- https://mail.python.org/mailman/listinfo/python-list
Re: Random ALL CAPS posts on this group
On Monday, January 19, 2015 at 6:16:13 PM UTC-6, Luke Tomaneng wrote: > Has anyone noticed [uppercase post content]? There have > been about three of them recently and they don't seem to > have anything to do with Python at all. Does anyone know > if there is a good reason they are here? A "good reason"...? Nope. Using all-caps when writing is understood as shouting. I sometimes use caps myself on intermittent words that need special emphasis, but using nothing but caps is so annoying that most people won't even bother to read your posts. Apparently the author has something "so important" to say, they he thinks he needs to "shout from the rafters" so everybody can hear his "important message". Although, he's failed to notice that this is a group who's primary focus is the Python Programming language, or at minimum, a discussion of technical issues, and so most people are not going to be interested -- and by "most" i mean *ALL*. ;-) However, as is the case with most of these "troll-spammers", the author is most likely posting this crap to multiple message boards in hopes that someone will engage him or click one of his malware installing links. Just ignore them. That's the beauty of free speech: "We have right to be annoyed, and the author has the right not to give a damn". The only alternative is fascist censorship, and I'll happily endure these annoyances to prevent that! You see, with fascism you just trade one annoying jerk who has no power, for another annoying jerk who has the absolute power of the state behind him -- and you know the old adage about power and corruption don't you? -- https://mail.python.org/mailman/listinfo/python-list
Re: Trees
In article , [email protected] says... > > Why aren't there trees in the python standard library? I don't know much about python development process and strategies, but I suspect it shouldn't be much different from any other language I know of. So here's my tentative answer: Once general purpose programming languages become established, the STL maintainers tend to greatly decrease additions to the standard library, except when this is required to support new language features. Most of development on the STL shifts to code maintenance in order to improve the quality of the code (usually to address memory usage and performance concerns) and solve any existing bugs on the STL. Instead the language maintainers start to rely on third-party libraries as a continuation of the effort to extend the programming language further. Any new additions to the STL are carefully pondered. The reason is twofold: 1) Just like with the matter of data structures, many additions are implementation-contentious. Trees, for instance, can be implemented in any number of ways, some with an emphasis on performance, others on memory usage. The decision of which implementation to choose isn't easy. And if users can already choose different types of implementations from the external libraries, then this is is probably motivation enough to delay the decision for another day. 2) A standard library should focus first and foremost on support of the language features. If for some reason this takes time away from adding new entries into the STL, that's fine. There's also the problem of how one should look at a standard library. Some maintainers don't look very well at the idea of a monolithic approach, while others, like Guido, like to think of a "batteries- included" programming language, indicating a desire to build a large STL. And this is why perhaps your question arises. But "batteries included" doesn't mean build a "Total Library". That would be a vain attempt for any general purpose language. -- https://mail.python.org/mailman/listinfo/python-list
Re: Random ALL CAPS posts on this group
Luke Tomaneng wrote: > Has anyone noticed these? There have been about three of them recently and > they don't seem to have anything to do with Python at all. Does anyone > know if there is a good reason they are here? They're spam, and depending on how you are accessing this group you may or may not see them. Alas I do see them. Just delete them, please please please please do not reply to them and try to argue with the spammer. Occasionally we have either well-meaning but foolish people who think that replying to spam, quoting the entire spam message in their email, and sending to the list is somehow helping. Of course the spammer isn't reading replies! Either that, or they are actually spammers themselves, and their cunning ploy is to *pretend* to be replying to spam in order to get their message past the spam filters. So don't be one of those guys. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Concerning Dictionaries and += in Python 2.x
On Tue, Jan 20, 2015 at 11:34 AM, Luke Tomaneng wrote: > Thanks Chris / Mr. Angelico / whatever you prefer. I attempted to post a > reply to you before but it could not be viewed even after refreshing several > times. You've been helpful. > My pleasure! Your earlier email did come through; sometimes there are short delays, it's not a big deal. As to a mode of address, most people use first names around here, so "Chris" is common. But when lots of Chrises get to talking, that can get ambiguous, so I might be referred to as ChrisA, or as Rosuav (my email address). But Mr Angelico is fine, if a little formal :) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Concerning Dictionaries and += in Python 2.x
On Mon, Jan 19, 2015 at 4:12 PM, Luke Tomaneng wrote:
> I have been having a bit of trouble with the things mentioned in the title. I
> have written the following script for a Codecademy course:
> stock = {
> "banana": 6,
> "apple": 0,
> "orange": 32,
> "pear": 15
> }
>
> prices = {
> "banana": 4,
> "apple": 2,
> "orange": 1.5,
> "pear": 3
> }
>
> def compute_bill(food):
> total = 0
> for item in food:
> if stock[item] > 0:
> total += prices[item]
> stock[item] = stock[item] - 1
> return total
> Whenever I run this script, "4" is returned. It does not seem to matter what
> in in the list the script is run on. I have tried this on the Codecademy
> interpreter/emulator (I'm not sure which they use) and the repl.it
> interpreter, but for the same result. If anyone could find the glitch in my
> code, please let me know. Thanks!
You're returning total inappropriately - the first time stock[item] is > 0.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Trees
On Mon, Jan 19, 2015 at 2:06 PM, Zachary Gilmartin wrote: > Why aren't there trees in the python standard library? Trees are kind of specialized datastructures; no one type of tree solves all tree-related problems suitably well. I think probably the most common need for a tree is implementing a cache, but most times you're tempted to sort inside a loop you're better off with a tree. I've put some time into python trees; most of them are on pypi and at: http://stromberg.dnsalias.org/~dstromberg/datastructures/ and: http://stromberg.dnsalias.org/~strombrg/python-tree-and-heap-comparison/ HTH -- https://mail.python.org/mailman/listinfo/python-list
Re: Random ALL CAPS posts on this group
On Tue, Jan 20, 2015 at 11:38 AM, Rick Johnson wrote: > That's the beauty of free speech: "We have right to be > annoyed, and the author has the right not to give a damn". > The only alternative is fascist censorship, and I'll happily > endure these annoyances to prevent that! Free speech also gives the freedom to not listen. Maybe it's less trouble to skip them manually than to filter them out reliably, but you do still have that option. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Random ALL CAPS posts on this group
Chris Angelico writes: > On Tue, Jan 20, 2015 at 11:38 AM, Rick Johnson > wrote: > > That's the beauty of free speech: "We have right to be annoyed, and > > the author has the right not to give a damn". The only alternative > > is fascist censorship, and I'll happily endure these annoyances to > > prevent that! > > Free speech also gives the freedom to not listen. Freedom of expression entails an obligation on the state to not quash anyone's expression. It does not affect anyone who is not the state; it imposes no obligation on the PSF. Freedom of expression has no implication that anyone else is obligated to listen, as you say. It also has no implication that anyone is obligated to carry that expression further. So a forum such as this can block obnoxious spam, and that choice does not impact anyone's freedom of expression. -- \ “I planted some bird seed. A bird came up. Now I don't know | `\ what to feed it.” —Steven Wright | _o__) | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: Storing dataset from Condtional FreqDist
> Hello i have trying to store information in arff file but i has been really.
> Any ideas of how can i do that?
>
>
> with open('fileids3.txt', 'r') as f:
>
> genres=[word.strip() for word in f.next().split(',')]
>
> with open('adjectifs2.txt', 'r') as g:
> adj = [word.strip() for word in g.next().split(',')]
>
> freq = nltk.ConditionalFreqDist(
> (genre, m)
> for genre in brown.fileids()
> for m in brown.words(fileids=genre))
>
>
> freq.tabulate(conditions=genres, samples=adj)
What do fileids3.txt and adjectifs2.txt contain (perhaps give us the
first few lines of each)?
What do you want your AARF file to look like (show us what the header
should look like and then the first few lines of data)?
--
https://mail.python.org/mailman/listinfo/python-list
Re: Trees
On 20/01/2015 00:49, Dan Stromberg wrote: On Mon, Jan 19, 2015 at 2:06 PM, Zachary Gilmartin wrote: Why aren't there trees in the python standard library? Trees are kind of specialized datastructures; no one type of tree solves all tree-related problems suitably well. I think probably the most common need for a tree is implementing a cache, but most times you're tempted to sort inside a loop you're better off with a tree. I've put some time into python trees; most of them are on pypi and at: http://stromberg.dnsalias.org/~dstromberg/datastructures/ and: http://stromberg.dnsalias.org/~strombrg/python-tree-and-heap-comparison/ HTH I don't know if you've seen this http://kmike.ru/python-data-structures/ but maybe of interest. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Random ALL CAPS posts on this group
On 20/01/2015 00:15, Luke Tomaneng wrote: Has anyone noticed these? There have been about three of them recently and they don't seem to have anything to do with Python at all. Does anyone know if there is a good reason they are here? I've never seen any of these reading gmane.comp.python.general using Thunderbird. The only annoying things I recall recently are bvbvbvbv and the Italian Mob. Whenever I spot them I'm straight onto gg to flag them as abuse. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Random ALL CAPS posts on this group
On Monday, January 19, 2015 at 7:55:11 PM UTC-6, Chris Angelico wrote: > On Tue, Jan 20, 2015 at 11:38 AM, Rick Johnson wrote: > > That's the beauty of free speech: "We have right to be > > annoyed, and the author has the right not to give a damn". > > The only alternative is fascist censorship, and I'll happily > > endure these annoyances to prevent that! > > Free speech also gives the freedom to not listen. Maybe it's less > trouble to skip them manually than to filter them out reliably, but > you do still have that option. Agreed. Listening is not compulsory. Fingers stuck firmly in the ear canals or utilizing the natural phenomenon that sound waves tend to diminish over distances, or when passing through physical obstructions, are all effective techniques! Of course the "kill file" has such a gloriously revengeful sound to it though! ;-) -- https://mail.python.org/mailman/listinfo/python-list
Re: Random ALL CAPS posts on this group
On Tue, Jan 20, 2015 at 2:50 PM, Rick Johnson wrote: > Of course the "kill file" has such a gloriously revengeful > sound to it though! ;-) http://bofh.ntk.net/BOFH//bastard-sm2.php ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Random ALL CAPS posts on this group
On Monday, January 19, 2015 at 8:16:01 PM UTC-6, Ben Finney wrote: > Freedom of expression entails an obligation on the state > to not quash anyone's expression. It does not affect > anyone who is not the state; it imposes no obligation on > the PSF. [...] So a forum such as this can block obnoxious > spam, and that choice does not impact anyone's freedom of > expression. Ben, i know we have not agreed much in the past, and you may be thinking that i intend to pick a fight with you here (and i don't), however i implore you to give more thought to the vital importance of free expression. I believe that free speech is so important, so vital to the existence of free societies, that it's practice *MUST* extend far beyond the boundaries of the state's rule, and be fostered by *ANY* group who is in the public domain. No one here would justify a public business refusing to serve or employ a person based on race, religion, sex, or otherwise. So why would you so easily discriminate against speech? I agree that these spam posts are annoying, but that is not enough of an excuse to start limiting people's speech in a *PUBLIC* forum. If python-list were a private group for "members only", then by all means make up whatever rules you want to. But when shared publicly, we have a duty to support freedom for *ALL*. We must suffer the annoyances if we want to enjoy freedom for all. -- https://mail.python.org/mailman/listinfo/python-list
Re: Trees
On Mon, Jan 19, 2015 at 6:46 PM, Mark Lawrence wrote: > On 20/01/2015 00:49, Dan Stromberg wrote: >> >> On Mon, Jan 19, 2015 at 2:06 PM, Zachary Gilmartin >> wrote: >>> >>> Why aren't there trees in the python standard library? >> >> >> Trees are kind of specialized datastructures; no one type of tree >> solves all tree-related problems suitably well. >> >> I think probably the most common need for a tree is implementing a >> cache, but most times you're tempted to sort inside a loop you're >> better off with a tree. >> >> I've put some time into python trees; most of them are on pypi and at: >> http://stromberg.dnsalias.org/~dstromberg/datastructures/ >> and: >> http://stromberg.dnsalias.org/~strombrg/python-tree-and-heap-comparison/ >> >> HTH >> > > I don't know if you've seen this http://kmike.ru/python-data-structures/ but > maybe of interest. I've seen it. It's a nice page. I attempted to get my treap port in there since it has a Cython version, but it didn't seem to take. I've mostly focused on pure python that runs on CPython 2.x, CPython 3.x, Pypy, Pypy3 and Jython. -- https://mail.python.org/mailman/listinfo/python-list
Re: Trees
On Mon, Jan 19, 2015 at 11:21 PM, Dan Stromberg wrote: > On Mon, Jan 19, 2015 at 6:46 PM, Mark Lawrence > wrote: > > On 20/01/2015 00:49, Dan Stromberg wrote: > >> > apropos of nothing, I went to stonybrook too. beee 1978 > >> On Mon, Jan 19, 2015 at 2:06 PM, Zachary Gilmartin > >> wrote: > >>> > >>> Why aren't there trees in the python standard library? > >> > >> > >> Trees are kind of specialized datastructures; no one type of tree > >> solves all tree-related problems suitably well. > >> > >> I think probably the most common need for a tree is implementing a > >> cache, but most times you're tempted to sort inside a loop you're > >> better off with a tree. > >> > >> I've put some time into python trees; most of them are on pypi and at: > >> http://stromberg.dnsalias.org/~dstromberg/datastructures/ > >> and: > >> > http://stromberg.dnsalias.org/~strombrg/python-tree-and-heap-comparison/ > >> > >> HTH > >> > > > > I don't know if you've seen this http://kmike.ru/python-data-structures/ > but > > maybe of interest. > > I've seen it. It's a nice page. > > I attempted to get my treap port in there since it has a Cython > version, but it didn't seem to take. > > I've mostly focused on pure python that runs on CPython 2.x, CPython > 3.x, Pypy, Pypy3 and Jython. > -- > https://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Trees
Mark Lawrence : > On 19/01/2015 22:06, Zachary Gilmartin wrote: >> Why aren't there trees in the python standard library? > > Probably because you'd never get agreement as to which specific tree > and which specific implementation was the most suitable for inclusion. Most programming languages provide one standard sorted mapping implementation. GvR is highly suspicious of the utility of trees and wouldn't like to take the burden of maintaining them in the stdlib. So in my Python software (both at work and at home) needs, I use a Python AVL tree implementation of my own. My use case is timers. (GvR uses heapq for the purpose.) Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: Trees
On 1/19/2015 5:06 PM, Zachary Gilmartin wrote: Why aren't there trees in the python standard library? Sequences nested withing sequences can be regarded as trees, and Python has these. I regard Lisp as a tree processing languages, as it must be to manipulate, for example, code with nested structures. Nested structures in general represent trees or more general graph forms. The ast module uses Nodes with lists of subnodes to represent Abstract Syntax Trees. Priority queues are specialized trees implemented on top of lists. The heapq module is imported into 6 other modules. Others have answered as to why other special-purpose constrained-structure trees have not been added to the stdlib. It might possibly be useful to add a general Tree base class with pre-, in-, and post-order generators, and maybe interior and leaf node counters and max depth method. Finding uses for such a thing in the stdlib (ast?) would be a plus in favor. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Bodybuilding Helpful Advice
Refuel Extreme helps control bloodflow in the body and so it helps determine mental performance, lungs, and also other important organs. This is one of many Best Bodybuilding Supplements you're able to take. It works within the skeletal muscles and will help communications are sent by the human body over a cellular-level. So you have more result for whatever exercise you place in, it supposedly helps with growth hormones. Refuel Extreme in mind that deadlifts are a few of the very most miserable and strenuous exercises you'll ever run into. Should you them appropriately, deadlifts can leave you lightheaded, a little queasy for atmosphere, and ultimately will have you wishing you werenot a member of the gym at all. You can do provided that you want benefits, you are going to need to stay with it as itis the Best Bodybuilding workout. http://tadvancesite.com/refuel-extreme-review/ -- View this message in context: http://python.6.x6.nabble.com/Bodybuilding-Helpful-Advice-tp5083763.html Sent from the Python - python-list mailing list archive at Nabble.com. -- https://mail.python.org/mailman/listinfo/python-list
