Giter Site home page Giter Site logo

hansalemaos / namedtuple_from_dict Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 1 KB

namedtuple from dict / valid identifier from string

Home Page: https://pypi.org/project/namedtuple-from-dict/

License: MIT License

Python 100.00%
dict namedtuple python

namedtuple_from_dict's Introduction

namedtuple from dict / valid identifier from string

# Tested with:
# Python 3.9.13
# Windows 10

pip install namedtuple-from-dict

from namedtuple_from_dict import create_valid_identifier, dict_to_namedtuple

from string import printable
from random import choices, randrange

# startwith will be added if the original string starts with a number
# 9times6 -> aa_9times6

testdict = {
    1: "hallo",
    "n k q": 223,
    (1, 2, 4): {222, 333},
    "validkey1": "test",
    "validkey2": "tes1t",
    "notvalidkey!1": "tes1t",
}

testtuple = dict_to_namedtuple(dic=testdict, name="testdata", startwith="aa_")

print(testtuple)
for i in range(10):
    randomchars = "".join(choices(printable, k=randrange(3, 10)))
    varname = create_valid_identifier(randomchars, startwith="aa_")
    print(f"{randomchars=}")
    print(f"{varname=}")


# testdata(aa_1='hallo', n_k_q=223, aa_1_2_4={333, 222}, validkey1='test', validkey2='tes1t', notvalidkey_1='tes1t')
# randomchars=':ga(F'
# varname='ga_F'
# randomchars='lh[)iN>A/'
# varname='lh_iN_A'
# randomchars='fI&mE)'
# varname='fI_mE'
# randomchars='//YW'
# varname='YW'
# randomchars='aY\x0c'
# varname='aY'
# randomchars='k|\ts \x0b'
# varname='k_s'
# randomchars='!kGhJ`'
# varname='kGhJ'
# randomchars='8u*s'
# varname='aa_8u_s'
# randomchars='\\z;_cP'
# varname='z__cP'
# randomchars='e)=Qb\t7p'
# varname='e_Qb_7p'

	

namedtuple_from_dict's People

Contributors

hansalemaos avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.